couchbase: Add document id to vector search results (#27622)

**Description:** Returns the document id along with the Vector Search
results

**Issue:** Fixes https://github.com/langchain-ai/langchain/issues/26860
for CouchbaseVectorStore


- [x] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified.

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Nithish Raghunandanan
2024-10-24 23:47:36 +02:00
committed by GitHub
parent 455ab7d714
commit 0623c74560
3 changed files with 33 additions and 2 deletions

View File

@@ -559,12 +559,13 @@ class CouchbaseVectorStore(VectorStore):
# Parse the results
for row in search_iter.rows():
text = row.fields.pop(self._text_key, "")
id = row.id
# Format the metadata from Couchbase
metadata = self._format_metadata(row.fields)
score = row.score
doc = Document(page_content=text, metadata=metadata)
doc = Document(id=id, page_content=text, metadata=metadata)
docs_with_score.append((doc, score))
except Exception as e: