You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain.js documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain.js rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
The following code:
import{MemoryVectorStore}from"langchain/vectorstores/memory";import{Document}from"@langchain/core/documents";import{OpenAIEmbeddings}from"@langchain/openai";importdotenvfrom"dotenv";dotenv.config();constembeddings=newOpenAIEmbeddings();constdocs=[newDocument({metadata: {id: '1'},pageContent: 'Document related to test',id: '1'})];constms=MemoryVectorStore.fromDocuments(docs,embeddings).then(ms=>{ms.asRetriever().invoke('test').then((docs)=>console.log(docs));});
Prints
[
Document {
pageContent: 'Document related to test',
metadata: { id: '1' },
id: undefined
}
]
Note that id is undefined
Error Message and Stack Trace (if applicable)
No response
Description
When storing Documents with id field in MemoryVectorStore and then retrieving, the id is not retrieved.
System Info
All
The text was updated successfully, but these errors were encountered:
@dschenkelman Hello there! I'm here to assist you with any bugs, questions, or contributions you have regarding this repository.
The id field of a Document becomes undefined when storing and retrieving it using MemoryVectorStore in LangChain.js because the idKey used to store and retrieve the document IDs is set to "doc_id" by default. If the documents do not have a metadata field with this key, the IDs will not be correctly stored or retrieved.
To fix this, ensure that the documents have the correct metadata field for the ID, or set the idKey to match the metadata field used in your documents. For example, if your documents use "id" as the metadata key for IDs, initialize the MultiVectorRetriever with idKey: "id":
Additionally, ensure that the metadata field includes the correct ID key when saving context to maintain the association between document IDs and their content [1][2][3][4].
Checked other resources
Example Code
The following code:
Prints
Note that
id
is undefinedError Message and Stack Trace (if applicable)
No response
Description
When storing
Document
s withid
field inMemoryVectorStore
and then retrieving, theid
is not retrieved.System Info
All
The text was updated successfully, but these errors were encountered: