Skip to content

Commit

Permalink
fix for required dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Feb 16, 2024
1 parent 17868e9 commit 63f30bb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions langchain_iris/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class IRISVector(VectorStore):
def __init__(
self,
embedding_function: Embeddings,
dimension: int,
dimension: int = None,
connection_string: Optional[str] = None,
collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME,
pre_delete_collection: bool = False,
Expand All @@ -95,6 +95,9 @@ def __init__(
) -> None:
self.connection_string = connection_string or "iris+emb:///"
self.embedding_function = embedding_function
if not dimension:
sample_embedding = embedding_function.embed_query("Hello IRISVector!")
dimension = len(sample_embedding)
self.dimension = dimension
self.collection_name = collection_name
self.pre_delete_collection = pre_delete_collection
Expand Down Expand Up @@ -315,7 +318,6 @@ def _select_relevance_score_fn(self) -> Callable[[float], float]:

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

return round(1.0 - distance, 15)
Expand Down Expand Up @@ -375,12 +377,8 @@ def from_texts(
Return VectorStore initialized from texts and embeddings.
"""

sample_embedding = embedding.embed_query("Hello IRISVector!")
dimension = len(sample_embedding)

store = cls(
collection_name=collection_name,
dimension=dimension,
distance_strategy=distance_strategy,
embedding_function=embedding,
pre_delete_collection=pre_delete_collection,
Expand Down

0 comments on commit 63f30bb

Please sign in to comment.