Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fixed qodo reviews

Sameer6305248d028b09b7
diff --git a/semantica/vector_store/faiss_store.py b/semantica/vector_store/faiss_store.py
index 41045ec5..7a2ef4b8 100644
--- a/semantica/vector_store/faiss_store.py
+++ b/semantica/vector_store/faiss_store.py
@@ -93,7 +93,7 @@ class FAISSIndex:
def get_metadata(self, vector_id: str) -> Optional[Dict[str, Any]]:
"""Get metadata by ID."""
- raise NotImplementedError("FAISS does not store metadata natively. Please use a secondary metadata store.")
+ return self.metadata.get(vector_id)
def save(self, path: Union[str, Path]):
"""Save index to disk."""
diff --git a/semantica/vector_store/milvus_store.py b/semantica/vector_store/milvus_store.py
index 700da668..af88567b 100644
--- a/semantica/vector_store/milvus_store.py
+++ b/semantica/vector_store/milvus_store.py
@@ -342,9 +342,10 @@ class MilvusStore:
# Define schema
fields = [
FieldSchema(
- name="id", dtype=DataType.INT64, is_primary=True, auto_id=True
+ name="id", dtype=DataType.VARCHAR, is_primary=True, auto_id=False, max_length=65535
),
FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=dimension),
+ FieldSchema(name="metadata", dtype=DataType.JSON),
]
schema = CollectionSchema(
@@ -398,18 +399,24 @@ class MilvusStore:
except Exception as e:
raise ProcessingError(f"Failed to get collection: {str(e)}")
- def insert_vectors(
- self, vectors: List[Union[np.ndarray, List[float]]], **options
- ) -> Any:
+ def add_vectors(
+ self,
+ vectors: List[Union[np.ndarray, List[float]]],
+ ids: Optional[List[str]] = None,
+ metadata: Optional[List[Dict[str, Any]]] = None,
+ **options
+ ) -> List[str]:
"""
- Insert vectors into collection.
+ Add vectors to collection.
Args:
vectors: List of vectors
+ ids: Optional list of vector IDs
+ metadata: Optional list of metadata dictionaries
**options: Additional options
Returns:
- Insert result
+ List of vector IDs
"""
tracking_id = self.progress_tracker.start_tracking(
module="vector_store",
@@ -442,7 +449,15 @@ class MilvusStore:
vector = vector.tolist()
vector_data.append(vector)
- data = [vector_data]
+ import uuid
+ if ids is None:
+ ids = [str(uuid.uuid4()) for _ in range(len(vectors))]
+
+ if metadata is None:
+ metadata = [{} for _ in range(len(vectors))]
+
+ data = [ids, vector_data, metadata]
+
self.progress_tracker.update_tracking(
tracking_id, message="Inserting vectors into collection..."
)
@@ -453,7 +468,7 @@ class MilvusStore:
status="completed",
message=f"Inserted {len(vectors)} vectors",
)
- return result
+ return ids
except Exception as e:
self.progress_tracker.stop_tracking(
@@ -525,17 +540,35 @@ class MilvusStore:
def get_vector(self, vector_id: str) -> Optional[np.ndarray]:
"""Get vector by ID."""
- raise NotImplementedError(
- "MilvusStore generates its own INT64 primary keys via auto_id=True and drops string IDs "
- "during insertion, making direct ID lookup impossible."
- )
+ if not MILVUS_AVAILABLE or not self.collection:
+ return None
+
+ try:
+ res = self.collection.collection.query(
+ expr=f'id == "{vector_id}"',
+ output_fields=["vector"]
+ )
+ if res and len(res) > 0:
+ return np.array(res[0]["vector"])
+ return None
+ except Exception:
+ return None
def get_metadata(self, vector_id: str) -> Optional[Dict[str, Any]]:
"""Get metadata by ID."""
- raise NotImplementedError(
- "MilvusStore generates its own INT64 primary keys via auto_id=True and drops string IDs "
- "during insertion, making direct ID lookup impossible."
- )
+ if not MILVUS_AVAILABLE or not self.collection:
+ return None
+
+ try:
+ res = self.collection.collection.query(
+ expr=f'id == "{vector_id}"',
+ output_fields=["metadata"]
+ )
+ if res and len(res) > 0:
+ return res[0].get("metadata", {})
+ return None
+ except Exception:
+ return None
def get_stats(self, collection_name: Optional[str] = None) -> Dict[str, Any]:
"""Get collection statistics."""
diff --git a/semantica/vector_store/pgvector_store.py b/semantica/vector_store/pgvector_store.py
index e2d16810..89a57145 100644
--- a/semantica/vector_store/pgvector_store.py
+++ b/semantica/vector_store/pgvector_store.py
@@ -634,7 +634,7 @@ class PgVectorStore:
def get_vector(self, vector_id: str) -> Optional[np.ndarray]:
"""Get vector by ID."""
try:
- results = self.get_vectors([vector_id])
+ results = self.get([vector_id])
if results and len(results) > 0:
return results[0].get("vector")
return None
@@ -645,7 +645,7 @@ class PgVectorStore:
def get_metadata(self, vector_id: str) -> Optional[Dict[str, Any]]:
"""Get metadata by ID."""
try:
- results = self.get_vectors([vector_id])
+ results = self.get([vector_id])
if results and len(results) > 0:
return results[0].get("metadata")
return None
diff --git a/semantica/vector_store/sqlite_vec_store.py b/semantica/vector_store/sqlite_vec_store.py
index 57483808..776eb4a2 100644
--- a/semantica/vector_store/sqlite_vec_store.py
+++ b/semantica/vector_store/sqlite_vec_store.py
@@ -595,7 +595,7 @@ class SQLiteVecStore:
def get_vector(self, vector_id: str) -> Optional[np.ndarray]:
"""Get vector by ID."""
try:
- results = self.get_vectors([vector_id])
+ results = self.get([vector_id])
if results and len(results) > 0:
return results[0].get("vector")
return None
@@ -606,7 +606,7 @@ class SQLiteVecStore:
def get_metadata(self, vector_id: str) -> Optional[Dict[str, Any]]:
"""Get metadata by ID."""
try:
- results = self.get_vectors([vector_id])
+ results = self.get([vector_id])
if results and len(results) > 0:
return results[0].get("metadata")
return None
diff --git a/tests/vector_store/test_decision_embedding_pipeline.py b/tests/vector_store/test_decision_embedding_pipeline.py
index 4340693f..90e6d494 100644
--- a/tests/vector_store/test_decision_embedding_pipeline.py
+++ b/tests/vector_store/test_decision_embedding_pipeline.py
@@ -417,14 +417,14 @@ class TestVectorStoreRetrieval:
pytest.skip("FAISS not installed")
vs = VectorStore(backend="faiss", config={"dimension": 3})
- vs.store_vectors([np.array([0.1, 0.2, 0.3], dtype=np.float32)], ids=["test1"])
+ vs.store_vectors([np.array([0.1, 0.2, 0.3], dtype=np.float32)], ids=["test1"], metadata=[{"foo": "faiss_bar"}])
vec = vs.get_vector("test1")
assert vec is not None
np.testing.assert_array_almost_equal(vec, np.array([0.1, 0.2, 0.3], dtype=np.float32))
- with pytest.raises(NotImplementedError, match="does not store metadata"):
- vs.get_metadata("test1")
+ meta = vs.get_metadata("test1")
+ assert meta == {"foo": "faiss_bar"}
def test_cloud_backends_untested(self):
"""