diff --git a/docs/docs/integrations/vectorstores/tablestore.ipynb b/docs/docs/integrations/vectorstores/tablestore.ipynb index 0c82261d97f2d..5ff466a3b2562 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.py index a00e102839c0b..2a5d3b20568b8 100644 --- a/libs/community/langchain_community/vectorstores/tablestore.py +++ b/libs/community/langchain_community/vectorstores/tablestore.py @@ -458,6 +458,11 @@ def add_texts( 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.py index 4af879485d725..605da30d98ffe 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]