Replies: 2 comments 3 replies
-
🤖 Hey @jambudipa! I'm Dosu, a friendly bot here to help you navigate the world of LangChainJS, solve bugs, answer questions, and even guide you to become a contributor. While we're waiting for a human maintainer, feel free to ask me anything - I'm here to make your coding journey smoother. Let's dive into your issue! It seems like you're trying to use the
Now, to your question about why you're not getting any results when you remove the If you want to persist your documents between different instances of your application, you need to use a persistent document store. Unfortunately, the You might need to implement your own document store that can persist data in a format compatible with the Here's a simple example of how you might implement a file-based document store: class FileStore extends BaseStore<string, Document> {
constructor(private filePath: string) {
super();
}
async get(id: string): Promise<Document | undefined> {
const data = await fs.promises.readFile(this.filePath, 'utf-8');
const documents = JSON.parse(data);
return documents[id];
}
async set(id: string, value: Document): Promise<void> {
const data = await fs.promises.readFile(this.filePath, 'utf-8');
const documents = JSON.parse(data);
documents[id] = value;
await fs.promises.writeFile(this.filePath, JSON.stringify(documents));
}
} You can use this const docstore = new FileStore('./documents.json'); This will save your documents to a file named I hope this helps! If you have any more questions, feel free to ask. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosu-botWould it be possible to simply extend InMemoryStore to persist and restore the object to the file system?Sent from my iPhoneOn 23 Dec 2023, at 07:05, dosubot[bot] ***@***.***> wrote:
🤖
Based on the information provided in the examples/src/retrievers/parent_document_retriever.ts file, the LangChain JavaScript framework does indeed use the InMemoryStore as a document store. This store takes Document as a generic parameter and is compatible with the ParentDocumentRetriever.
However, as you've noted, the InMemoryStore does not persist data between different instances of your application. It's an in-memory store, meaning it only stores data for the duration of the application's runtime.
The LocalFileStore you tried using stores data as Uint8Array, which is not compatible with the ParentDocumentRetriever. This is likely because the LocalFileStore is designed to store binary data, while the ParentDocumentRetriever expects data in a different format.
Unfortunately, I couldn't find any other document stores provided by the LangChain framework that would meet your requirements. If you need a document store that persists data to a database, you might need to implement a custom document store. This custom store should implement the same interface as InMemoryStore to ensure compatibility with the ParentDocumentRetriever.
I hope this helps clarify the situation. If you have any further questions or if there's anything else you'd like to know, please don't hesitate to ask.
Sources
examples/src/retrievers/parent_document_retriever.ts
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I am really not understanding how to retrieve the parent documents using Langchain's
ParentDocumentRetriever
when using Pinecone. The following code is working for creating the embeddings and inserting them into Pinecone:The
retrievedDocs
contains a few parent documents, as expected.Now that my index is created, I would like to subsequently perform the same operation, but without the
await retriever.addDocuments(docs)
:This yields no results. The documentation is really rather unclear on this: am I expected to implement my own document store containing all of the parent documents with their accompanying IDs or something like that? Can I save the
InMemoryStore
to the filesystem, or use theLocalFileStore
? Does this document store pertain just to the parent documents?I am not sure how to use
LocalFileStore
since dropping it in as a replacement causes my IDE to become unhappy, because it extendsBaseStore<string, Uint8Array>
, whereasInMemoryStore
extendsBaseStore<string, T>
.In summary, how would I use Pinecone as a vector store in combination with
ParentDocumentRetriever
? What document store do I use? Does the docstore pertain to just the parent documents, is it necessary for me to store those myself?It seems to me that this would be a pretty common use case; where might I find an example?
Beta Was this translation helpful? Give feedback.
All reactions