Skip to content

Commit 4e00dcb

Browse files
committed
CrateDB vector: Fix initialization of vector dimensionality
1 parent 0d96827 commit 4e00dcb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

libs/langchain/langchain/vectorstores/cratedb/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ def create_tables_if_not_exists(self) -> None:
192192
"""
193193
Need to overwrite because this `Base` is different from parent's `Base`.
194194
"""
195-
mf = ModelFactory()
196-
mf.Base.metadata.create_all(self._engine)
195+
if self.BaseModel is None:
196+
raise RuntimeError("Storage models not initialized")
197+
self.BaseModel.metadata.create_all(self._engine)
197198

198199
def drop_tables(self) -> None:
199200
"""

libs/langchain/tests/integration_tests/vectorstores/test_cratedb.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@
2323
FakeEmbeddings,
2424
)
2525

26+
SCHEMA_NAME = os.environ.get("TEST_CRATEDB_DATABASE", "testdrive")
27+
2628
CONNECTION_STRING = CrateDBVectorSearch.connection_string_from_db_params(
2729
driver=os.environ.get("TEST_CRATEDB_DRIVER", "crate"),
2830
host=os.environ.get("TEST_CRATEDB_HOST", "localhost"),
2931
port=int(os.environ.get("TEST_CRATEDB_PORT", "4200")),
30-
database=os.environ.get("TEST_CRATEDB_DATABASE", "testdrive"),
32+
database=SCHEMA_NAME,
3133
user=os.environ.get("TEST_CRATEDB_USER", "crate"),
3234
password=os.environ.get("TEST_CRATEDB_PASSWORD", ""),
3335
)
3436

35-
36-
# TODO: Try 1536 after https://github.com/crate/crate/pull/14699.
37-
# ADA_TOKEN_COUNT = 14
38-
ADA_TOKEN_COUNT = 1024
39-
# ADA_TOKEN_COUNT = 1536
37+
ADA_TOKEN_COUNT = 1536
4038

4139

4240
@pytest.fixture
@@ -167,6 +165,25 @@ def test_cratedb_texts() -> None:
167165
assert output == [Document(page_content="foo")]
168166

169167

168+
def test_cratedb_embedding_dimension() -> None:
169+
"""Verify the `embedding` column uses the correct vector dimensionality."""
170+
texts = ["foo", "bar", "baz"]
171+
docsearch = CrateDBVectorSearch.from_texts(
172+
texts=texts,
173+
collection_name="test_collection",
174+
embedding=ConsistentFakeEmbeddingsWithAdaDimension(),
175+
connection_string=CONNECTION_STRING,
176+
pre_delete_collection=True,
177+
)
178+
with docsearch.Session() as session:
179+
result = session.execute(sa.text(f"SHOW CREATE TABLE {SCHEMA_NAME}.embedding"))
180+
record = result.first()
181+
if not record:
182+
raise ValueError("No data found")
183+
ddl = record[0]
184+
assert f'"embedding" FLOAT_VECTOR({ADA_TOKEN_COUNT})' in ddl
185+
186+
170187
def test_cratedb_embeddings() -> None:
171188
"""Test end to end construction with embeddings and search."""
172189
texts = ["foo", "bar", "baz"]

0 commit comments

Comments
 (0)