-
Checked other resources
Commit to Help
Example Code- DescriptionWhen I'm trying to use "PGVectorStore.similaritySearch(query, limit)", the results are like this [{metadata:{...},pageContent:""}], I want to get the document id also, how can I do that? System Infonode-ver: 16.20.1 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @Exlau! I'm here to assist you with any bugs, questions, or contributions you have. Let's tackle this together! To get the document ID when using Here is an example of how you can use this method: const results = await pgVectorStore.similaritySearchVectorWithScore(query, limit);
results.forEach(([document, score]) => {
console.log(`Document ID: ${document.id}, Score: ${score}`);
}); In this example, |
Beta Was this translation helpful? Give feedback.
-
Since similarity search returns only documents and documents do not include their id, there is currently no way to get the id when doing similarity search. If you insert with a custom id, you could also set that as an id-field in the metadata and retrieve it that way. Otherwise I'm afraid there is currently no other way except overwriting the PGVectorStore to include the id in the return. There's been some discussion about adding the id to the document interface and @jacoblee93 has mentioned that a new type of vectorstore/indexing integration is under works or at least being considered. |
Beta Was this translation helpful? Give feedback.
Since similarity search returns only documents and documents do not include their id, there is currently no way to get the id when doing similarity search. If you insert with a custom id, you could also set that as an id-field in the metadata and retrieve it that way. Otherwise I'm afraid there is currently no other way except overwriting the PGVectorStore to include the id in the return. There's been some discussion about adding the id to the document interface and @jacoblee93 has mentioned that a new type of vectorstore/indexing integration is under works or at least being considered.