fix(ts-sdk): make natural an optional peer so pg is not installed transitively
natural@8 hard-depends on pg ^8.18.0, mongoose, redis and memjs. As a required peer it was auto-installed for every mem0ai user, so pg stayed in the tree even after pg itself became optional. lemmatizeForBm25 already falls back to a built-in stemmer when natural is missing.
This commit is contained in:
@@ -263,6 +263,9 @@
|
|||||||
},
|
},
|
||||||
"@types/pg": {
|
"@types/pg": {
|
||||||
"optional": true
|
"optional": true
|
||||||
|
},
|
||||||
|
"natural": {
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+12
-2
@@ -2,7 +2,11 @@ jest.mock("pg", () => {
|
|||||||
throw new Error("Cannot find module 'pg'");
|
throw new Error("Cannot find module 'pg'");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("pg is an optional peer", () => {
|
jest.mock("natural", () => {
|
||||||
|
throw new Error("Cannot find module 'natural'");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("mem0ai/oss without pg or natural installed", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
@@ -11,7 +15,7 @@ describe("pg is an optional peer", () => {
|
|||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("mem0ai/oss loads without pg installed", async () => {
|
test("mem0ai/oss loads", async () => {
|
||||||
await expect(import("../src")).resolves.toHaveProperty("Memory");
|
await expect(import("../src")).resolves.toHaveProperty("Memory");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -26,4 +30,10 @@ describe("pg is an optional peer", () => {
|
|||||||
"The 'pg' package is required to use the PGVector vector store. Install it with: npm install pg",
|
"The 'pg' package is required to use the PGVector vector store. Install it with: npm install pg",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("BM25 lemmatization falls back to the built-in stemmer", async () => {
|
||||||
|
const { lemmatizeForBm25 } = await import("../src/utils/lemmatization");
|
||||||
|
|
||||||
|
expect(lemmatizeForBm25("The dogs were running")).toBe("dog runn running");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user