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:
kartik-mem0
2026-09-25 15:30:23 +05:30
parent 1b51ad5f89
commit 5a1225f8e9
2 changed files with 15 additions and 2 deletions
+3
View File
@@ -263,6 +263,9 @@
},
"@types/pg": {
"optional": true
},
"natural": {
"optional": true
}
},
"engines": {
@@ -2,7 +2,11 @@ jest.mock("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(() => {
jest.spyOn(console, "error").mockImplementation(() => {});
});
@@ -11,7 +15,7 @@ describe("pg is an optional peer", () => {
jest.restoreAllMocks();
});
test("mem0ai/oss loads without pg installed", async () => {
test("mem0ai/oss loads", async () => {
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",
);
});
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");
});
});