mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-31 08:32:32 +00:00
[Vector Store] Fix function add_texts
in TencentVectorDB
(#24469)
Regardless of whether `embedding_func` is set or not, the 'text' attribute of document should be assigned, otherwise the `page_content` in the document of the final search result will be lost
This commit is contained in:
parent
7ab82eb8cc
commit
0f6737cbfe
@ -375,8 +375,7 @@ class TencentVectorDB(VectorStore):
|
||||
}
|
||||
if embeddings:
|
||||
doc_attrs["vector"] = embeddings[id]
|
||||
else:
|
||||
doc_attrs["text"] = texts[id]
|
||||
doc_attrs["text"] = texts[id]
|
||||
doc_attrs.update(metadata)
|
||||
doc = self.document.Document(**doc_attrs)
|
||||
docs.append(doc)
|
||||
|
@ -85,3 +85,27 @@ def test_tencent_vector_db_no_drop() -> None:
|
||||
time.sleep(3)
|
||||
output = docsearch.similarity_search("foo", k=10)
|
||||
assert len(output) == 6
|
||||
|
||||
|
||||
def test_tencent_vector_db_add_texts_and_search_with_score() -> None:
|
||||
"""Test add texts to a new-created db and search with score."""
|
||||
texts = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
conn_params = ConnectionParams(
|
||||
url="http://10.0.X.X",
|
||||
key="eC4bLRy2va******************************",
|
||||
username="root",
|
||||
timeout=20,
|
||||
)
|
||||
docsearch = TencentVectorDB(
|
||||
embedding=FakeEmbeddings(),
|
||||
connection_params=conn_params,
|
||||
)
|
||||
docsearch.add_texts(texts, metadatas)
|
||||
output = docsearch.similarity_search_with_score("foo", k=3)
|
||||
docs = [o[0] for o in output]
|
||||
assert docs == [
|
||||
Document(page_content="foo", metadata={"page": 0}),
|
||||
Document(page_content="bar", metadata={"page": 1}),
|
||||
Document(page_content="baz", metadata={"page": 2}),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user