mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 06:14:37 +00:00
community: tablestore vector store check the dimension of the embedding when writing it to store. (#28812)
Added some restrictions to a vectorstore I released in the community before.
This commit is contained in:
parent
024f020f04
commit
97f1e1d39f
@ -8,10 +8,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"# TablestoreVectorStore\n",
|
"# Tablestore\n",
|
||||||
"\n",
|
"\n",
|
||||||
"> [Tablestore](https://www.aliyun.com/product/ots) is a fully managed NoSQL cloud database service that enables storage of a massive amount of structured\n",
|
"[Tablestore](https://www.aliyun.com/product/ots) is a fully managed NoSQL cloud database service.\n",
|
||||||
"and semi-structured data.\n",
|
"\n",
|
||||||
|
"Tablestore enables storage of a massive amount of structured and semi-structured data.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook shows how to use functionality related to the `Tablestore` vector database.\n",
|
"This notebook shows how to use functionality related to the `Tablestore` vector database.\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -458,6 +458,11 @@ class TablestoreVectorStore(VectorStore):
|
|||||||
row_id = ids[i]
|
row_id = ids[i]
|
||||||
text = text_list[i]
|
text = text_list[i]
|
||||||
embedding_vector = embeddings[i]
|
embedding_vector = embeddings[i]
|
||||||
|
if len(embedding_vector) != self.__vector_dimension:
|
||||||
|
raise RuntimeError(
|
||||||
|
"embedding vector size:%d is not the same as vector store dim:%d"
|
||||||
|
% (len(embedding_vector), self.__vector_dimension)
|
||||||
|
)
|
||||||
metadata = dict()
|
metadata = dict()
|
||||||
if metadatas and metadatas[i]:
|
if metadatas and metadatas[i]:
|
||||||
metadata = metadatas[i]
|
metadata = metadatas[i]
|
||||||
|
@ -91,3 +91,26 @@ def test_tablestore() -> None:
|
|||||||
"""
|
"""
|
||||||
search_result = store.similarity_search_with_score(query="hello world", k=2)
|
search_result = store.similarity_search_with_score(query="hello world", k=2)
|
||||||
assert len(search_result) == 2
|
assert len(search_result) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_tablestore_add_documents() -> None:
|
||||||
|
embeddings = FakeEmbeddings(size=128)
|
||||||
|
store = TablestoreVectorStore(
|
||||||
|
embedding=embeddings,
|
||||||
|
endpoint="http://test.a.com",
|
||||||
|
instance_name="test",
|
||||||
|
access_key_id="test",
|
||||||
|
access_key_secret="test",
|
||||||
|
vector_dimension=512,
|
||||||
|
)
|
||||||
|
doc = Document(
|
||||||
|
id="1",
|
||||||
|
page_content="1 hello world",
|
||||||
|
metadata={"type": "pc", "time": 2000},
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
store.add_documents([doc])
|
||||||
|
raise RuntimeError("should failed")
|
||||||
|
except Exception as e:
|
||||||
|
assert "not the same as" in e.args[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user