From 2aa43197adbb0adfce02f9195762386966c2f56c Mon Sep 17 00:00:00 2001 From: Drew Batshaw Date: Fri, 2 Aug 2024 16:38:39 -0700 Subject: [PATCH 1/2] Fix bug mongodb storage.ts When retrieving records the value was always JSON.stringified even if the value was already in JSON. As a result, MongoStore could not be used with standard retrievers like the ParentRetriever as it would always return documents with undefined for pageContent. --- libs/langchain-mongodb/src/storage.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/langchain-mongodb/src/storage.ts b/libs/langchain-mongodb/src/storage.ts index ce52f203c512..506484f4398f 100644 --- a/libs/langchain-mongodb/src/storage.ts +++ b/libs/langchain-mongodb/src/storage.ts @@ -103,8 +103,12 @@ export class MongoDBStore extends BaseStore { } if (value === undefined || value === null) { return undefined; - } else if (typeof value === "object") { + } + else if (typeof value.value === "object") { return encoder.encode(JSON.stringify(value.value)); + } + else if (typeof value.value === "string") { + return encoder.encode(value.value); } else { throw new Error("Unexpected value type"); } From a8e9cf67c9fbff12d6b4ae2362a41e4e0eab82e9 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Fri, 2 Aug 2024 18:01:36 -0700 Subject: [PATCH 2/2] Update storage.ts --- libs/langchain-mongodb/src/storage.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/langchain-mongodb/src/storage.ts b/libs/langchain-mongodb/src/storage.ts index 506484f4398f..528afbe5dbc8 100644 --- a/libs/langchain-mongodb/src/storage.ts +++ b/libs/langchain-mongodb/src/storage.ts @@ -103,12 +103,10 @@ export class MongoDBStore extends BaseStore { } if (value === undefined || value === null) { return undefined; - } - else if (typeof value.value === "object") { + } else if (typeof value.value === "object") { return encoder.encode(JSON.stringify(value.value)); - } - else if (typeof value.value === "string") { - return encoder.encode(value.value); + } else if (typeof value.value === "string") { + return encoder.encode(value.value); } else { throw new Error("Unexpected value type"); }