The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community: tablestore vector store check the dimension of the embedding when writing it to store. (#28812)
ScriptShi97f1e1d39ffa
diff --git a/docs/docs/integrations/vectorstores/tablestore.ipynb b/docs/docs/integrations/vectorstores/tablestore.ipynbindex 0c82261d97..5ff466a3b2 100644--- a/docs/docs/integrations/vectorstores/tablestore.ipynb+++ b/docs/docs/integrations/vectorstores/tablestore.ipynb@@ -8,10 +8,11 @@}},"source": [- "# TablestoreVectorStore\n",+ "# Tablestore\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",- "and semi-structured data.\n",+ "[Tablestore](https://www.aliyun.com/product/ots) is a fully managed NoSQL cloud database service.\n",+ "\n",+ "Tablestore enables storage of a massive amount of structured and semi-structured data.\n","\n","This notebook shows how to use functionality related to the `Tablestore` vector database.\n","\n",diff --git a/libs/community/langchain_community/vectorstores/tablestore.py b/libs/community/langchain_community/vectorstores/tablestore.pyindex a00e102839..2a5d3b2056 100644--- a/libs/community/langchain_community/vectorstores/tablestore.py+++ b/libs/community/langchain_community/vectorstores/tablestore.py@@ -458,6 +458,11 @@ class TablestoreVectorStore(VectorStore):row_id = ids[i]text = text_list[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()if metadatas and metadatas[i]:metadata = metadatas[i]diff --git a/libs/community/tests/integration_tests/vectorstores/test_tablestore.py b/libs/community/tests/integration_tests/vectorstores/test_tablestore.pyindex 4af879485d..605da30d98 100644--- a/libs/community/tests/integration_tests/vectorstores/test_tablestore.py+++ b/libs/community/tests/integration_tests/vectorstores/test_tablestore.py@@ -91,3 +91,26 @@ def test_tablestore() -> None:"""search_result = store.similarity_search_with_score(query="hello world", k=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]