fix(vector-stores): Supabase 1000-row cap, RLS init probe, and col_info crash (#6695)
This commit is contained in:
@@ -14,6 +14,8 @@ from mem0.vector_stores.base import VectorStoreBase
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
VECS_MAX_QUERY_LIMIT = 1000
|
||||
|
||||
|
||||
class OutputData(BaseModel):
|
||||
id: Optional[str]
|
||||
@@ -131,11 +133,21 @@ class Supabase(VectorStoreBase):
|
||||
List[OutputData]: Search results
|
||||
"""
|
||||
filters = self._preprocess_filters(filters)
|
||||
limit = top_k
|
||||
if limit > VECS_MAX_QUERY_LIMIT:
|
||||
logger.warning(
|
||||
f"Requested top_k={top_k} exceeds the vecs query limit of {VECS_MAX_QUERY_LIMIT}; "
|
||||
f"capping to {VECS_MAX_QUERY_LIMIT}."
|
||||
)
|
||||
limit = VECS_MAX_QUERY_LIMIT
|
||||
results = self.collection.query(
|
||||
data=vectors, limit=top_k, filters=filters, include_metadata=True, include_value=True
|
||||
data=vectors, limit=limit, filters=filters, include_metadata=True, include_value=True
|
||||
)
|
||||
|
||||
return [OutputData(id=str(result[0]), score=max(0.0, 1.0 - float(result[1])), payload=result[2]) for result in results]
|
||||
return [
|
||||
OutputData(id=str(result[0]), score=max(0.0, 1.0 - float(result[1])), payload=result[2])
|
||||
for result in results
|
||||
]
|
||||
|
||||
def delete(self, vector_id: str):
|
||||
"""
|
||||
@@ -201,12 +213,15 @@ class Supabase(VectorStoreBase):
|
||||
Returns:
|
||||
Dict: Collection information including name and configuration
|
||||
"""
|
||||
info = self.collection.describe()
|
||||
return {
|
||||
"name": info.name,
|
||||
"count": info.vectors,
|
||||
"dimension": info.dimension,
|
||||
"index": {"method": info.index_method, "metric": info.distance_metric},
|
||||
"name": self.collection.name,
|
||||
"count": len(self.collection),
|
||||
"dimension": self.collection.dimension,
|
||||
"index": {
|
||||
"name": self.collection.index,
|
||||
"measure": self.index_measure.value,
|
||||
"is_indexed": self.collection.is_indexed_for_measure(self.index_measure),
|
||||
},
|
||||
}
|
||||
|
||||
def list(self, filters: Optional[dict] = None, top_k: int = 100) -> List[OutputData]:
|
||||
@@ -222,8 +237,15 @@ class Supabase(VectorStoreBase):
|
||||
"""
|
||||
filters = self._preprocess_filters(filters)
|
||||
query = [0] * self.embedding_model_dims
|
||||
limit = top_k
|
||||
if limit > VECS_MAX_QUERY_LIMIT:
|
||||
logger.warning(
|
||||
f"Requested top_k={top_k} exceeds the vecs query limit of {VECS_MAX_QUERY_LIMIT}; "
|
||||
f"capping to {VECS_MAX_QUERY_LIMIT}."
|
||||
)
|
||||
limit = VECS_MAX_QUERY_LIMIT
|
||||
ids = self.collection.query(
|
||||
data=query, limit=top_k, filters=filters, include_metadata=True, include_value=False
|
||||
data=query, limit=limit, filters=filters, include_metadata=True, include_value=False
|
||||
)
|
||||
ids = [id[0] for id in ids]
|
||||
records = self.collection.fetch(ids=ids)
|
||||
|
||||
Reference in New Issue
Block a user