Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure ai vector store #2396

Merged
merged 3 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions docs/components/vectordbs/dbs/azure_ai_search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ messages = [
m.add(messages, user_id="alice", metadata={"category": "movies"})
```

## Advanced Usage

```python
# Search with specific filter mode
result = m.search(
"sci-fi movies",
filters={"user_id": "alice"},
limit=5,
vector_filter_mode="preFilter" # Apply filters before vector search
)

# Using binary compression for large vector collections
config = {
"vector_store": {
Expand Down Expand Up @@ -78,10 +67,6 @@ config = {
- `scalar`: Scalar quantization with reasonable balance of speed and accuracy
- `binary`: Binary quantization for maximum compression with some accuracy trade-off

- **vector_filter_mode**:
- `preFilter`: Applies filters before vector search (faster)
- `postFilter`: Applies filters after vector search (may provide better relevance)

- **use_float16**: Using half precision (float16) reduces storage requirements but may slightly impact accuracy. Useful for very large vector collections.

- **Filterable Fields**: The implementation automatically extracts `user_id`, `run_id`, and `agent_id` fields from payloads for filtering.
15 changes: 6 additions & 9 deletions mem0/vector_stores/azure_ai_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def insert(self, vectors, payloads=None, ids=None):
]
response = self.search_client.upload_documents(documents)
for doc in response:
if not doc.get("status", False):
if not hasattr(doc, "status_code") and doc.get("status_code") != 201:
raise Exception(f"Insert failed for document {doc.get('id')}: {doc}")
return response

Expand All @@ -189,16 +189,14 @@ def _build_filter_expression(self, filters):
filter_expression = " and ".join(filter_conditions)
return filter_expression

def search(self, query, limit=5, filters=None, vector_filter_mode="preFilter"):
def search(self, query, limit=5, filters=None):
"""
Search for similar vectors.

Args:
query (List[float]): Query vector.
limit (int, optional): Number of results to return. Defaults to 5.
filters (Dict, optional): Filters to apply to the search. Defaults to None.
vector_filter_mode (str): Determines whether filters are applied before or after the vector search.
Known values: "preFilter" (default) and "postFilter".

Returns:
List[OutputData]: Search results.
Expand All @@ -213,8 +211,7 @@ def search(self, query, limit=5, filters=None, vector_filter_mode="preFilter"):
search_results = self.search_client.search(
vector_queries=[vector_query],
filter=filter_expression,
top=limit,
vector_filter_mode=vector_filter_mode,
top=limit
)

results = []
Expand All @@ -236,7 +233,7 @@ def delete(self, vector_id):
"""
response = self.search_client.delete_documents(documents=[{"id": vector_id}])
for doc in response:
if not doc.get("status", False):
if not hasattr(doc, "status_code") and doc.get("status_code") != 200:
raise Exception(f"Delete failed for document {vector_id}: {doc}")
logger.info(f"Deleted document with ID '{vector_id}' from index '{self.index_name}'.")
return response
Expand All @@ -260,7 +257,7 @@ def update(self, vector_id, vector=None, payload=None):
document[field] = payload.get(field)
response = self.search_client.merge_or_upload_documents(documents=[document])
for doc in response:
if not doc.get("status", False):
if not hasattr(doc, "status_code") and doc.get("status_code") != 200:
raise Exception(f"Update failed for document {vector_id}: {doc}")
return response

Expand Down Expand Up @@ -335,7 +332,7 @@ def list(self, filters=None, limit=100):
id=result["id"], score=result["@search.score"], payload=payload
)
)
return results
return [results]

def __del__(self):
"""Close the search client when the object is deleted."""
Expand Down
86 changes: 74 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mem0ai"
version = "0.1.69"
version = "0.1.70"
description = "Long-term memory for AI Agents"
authors = ["Mem0 <[email protected]>"]
exclude = [
Expand Down
Loading