Skip to content

Commit 63f30bb

Browse files
committed
fix for required dimension
1 parent 17868e9 commit 63f30bb

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

langchain_iris/vectorstores.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class IRISVector(VectorStore):
8282
def __init__(
8383
self,
8484
embedding_function: Embeddings,
85-
dimension: int,
85+
dimension: int = None,
8686
connection_string: Optional[str] = None,
8787
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
8888
pre_delete_collection: bool = False,
@@ -95,6 +95,9 @@ def __init__(
9595
) -> None:
9696
self.connection_string = connection_string or "iris+emb:///"
9797
self.embedding_function = embedding_function
98+
if not dimension:
99+
sample_embedding = embedding_function.embed_query("Hello IRISVector!")
100+
dimension = len(sample_embedding)
98101
self.dimension = dimension
99102
self.collection_name = collection_name
100103
self.pre_delete_collection = pre_delete_collection
@@ -315,7 +318,6 @@ def _select_relevance_score_fn(self) -> Callable[[float], float]:
315318

316319
@staticmethod
317320
def _cosine_relevance_score_fn(distance: float) -> float:
318-
print('_cosine_relevance_score_fn', distance)
319321
"""Normalize the distance to a score on a scale [0, 1]."""
320322

321323
return round(1.0 - distance, 15)
@@ -375,12 +377,8 @@ def from_texts(
375377
Return VectorStore initialized from texts and embeddings.
376378
"""
377379

378-
sample_embedding = embedding.embed_query("Hello IRISVector!")
379-
dimension = len(sample_embedding)
380-
381380
store = cls(
382381
collection_name=collection_name,
383-
dimension=dimension,
384382
distance_strategy=distance_strategy,
385383
embedding_function=embedding,
386384
pre_delete_collection=pre_delete_collection,

0 commit comments

Comments
 (0)