Skip to content

Commit

Permalink
default vector id
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo committed Jul 2, 2024
1 parent dafb0a4 commit a8b0dba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions griptape/drivers/vector/base_vector_store_driver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import uuid
from abc import ABC, abstractmethod
from concurrent import futures
from dataclasses import dataclass
Expand Down Expand Up @@ -56,7 +57,7 @@ def upsert_text_artifact(
**kwargs,
) -> str:
meta = {} if meta is None else meta
vector_id = utils.str_to_hash(artifact.to_text()) if vector_id is None else vector_id
vector_id = self._get_default_vector_id(artifact.to_text()) if vector_id is None else vector_id

if self.does_entry_exist(vector_id, namespace):
return vector_id
Expand All @@ -81,7 +82,7 @@ def upsert_text(
meta: Optional[dict] = None,
**kwargs,
) -> str:
vector_id = utils.str_to_hash(string) if vector_id is None else vector_id
vector_id = self._get_default_vector_id(string) if vector_id is None else vector_id

if self.does_entry_exist(vector_id, namespace):
return vector_id
Expand Down Expand Up @@ -134,3 +135,6 @@ def query(
include_vectors: bool = False,
**kwargs,
) -> list[Entry]: ...

def _get_default_vector_id(self, value: str) -> str:
return str(uuid.uuid5(uuid.NAMESPACE_OID, value))
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def driver(self):
def test_upsert_text_artifact(self, driver):
artifact = TextArtifact("foo")

assert driver.upsert_text_artifact(artifact) == utils.str_to_hash(artifact.value)
assert driver.upsert_text_artifact(artifact) == driver._get_default_vector_id("foo")

def test_upsert_vector(self, driver):
assert driver.upsert_vector([0, 1, 2], vector_id="foo") == "foo"
Expand Down

0 comments on commit a8b0dba

Please sign in to comment.