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

[Bug] $and Operator in Metadata Filter for assistant.chat_completions Causes 400 Error #428

Open
ht290 opened this issue Jan 6, 2025 · 0 comments
Labels
bug Something isn't working status:needs-triage An issue that needs to be triaged by the Pinecone team

Comments

@ht290
Copy link

ht290 commented Jan 6, 2025

Here’s the rewritten bug report in the requested template format:

Is this a new bug?
• I believe this is a new bug
• I have searched the existing Github issues and Community Forum, and I could not find an existing post for this bug

Describe the bug
The $and operator in the metadata filter for assistant.chat_completions appears to cause a 400 Client Error. This issue contradicts the documentation, which suggests that $and should be supported (as per https://www.pinecone.io/learn/assistant-api-deep-dive/#Using-Metadata).

Error information
The API returns the following error:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://prod-1-data.ke.pinecone.io/assistant/chat/test/chat/completions
...
ValueError: Error in chat completions streaming: 400 Client Error: Bad Request for url: https://prod-1-data.ke.pinecone.io/assistant/chat/test/chat/completions

Relevant code snippet:

metadata_filter = {
    "$and": [
        {"date": {"$gte": 1698969600}},  # Unix timestamp for 2023-11-03
        {"date": {"$lte": 1699142400}}   # Unix timestamp for 2023-11-05
    ]
}

response = assistant.chat_completions(
    messages=chat_context,
    stream=True,
    filter=metadata_filter
)

File metadata used for testing:

[FileModel(name='file-4.txt', id='66228d1a-ac09-408c-be81-bb39cee82b0f', metadata={'date': 1699056000.0, 'source': 'test/file-4.txt'}, ...),
 FileModel(name='file-5.txt', id='a294006d-8d5f-45ff-ab90-9873467a4ae9', metadata={'date': 1699142400.0, 'source': 'test/file-5.txt'}, ...),
 FileModel(name='file-3.txt', id='c6d652d8-a356-4d10-b1bb-5808b8b7cad5', metadata={'date': 1698969600.0, 'source': 'test/file-3.txt'}, ...)]

Steps to reproduce the issue locally
1. Set up a metadata filter using the $and operator:

metadata_filter = {
    "$and": [
        {"date": {"$gte": 1698969600}},
        {"date": {"$lte": 1699142400}}
    ]
}
2.	Call assistant.chat_completions with the filter.
3.	Observe the 400 Client Error returned by the API.

Environment
• OS Version: macOS 14.4.1
• Python version: 3.11
• Python SDK version: Pinecone: 5.4.2, Pinecone-plugin-assistant: 0.4.3

Additional context
The documentation explicitly mentions $and as a valid operator, but it does not seem to function as expected in practice. Please confirm if this is a documentation error, an implementation bug, or an unsupported feature.

@ht290 ht290 added the bug Something isn't working label Jan 6, 2025
@github-actions github-actions bot added the status:needs-triage An issue that needs to be triaged by the Pinecone team label Jan 6, 2025
@ht290 ht290 changed the title [Bug] [Bug] $and Operator in Metadata Filter for assistant.chat_completions Causes 400 Error Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status:needs-triage An issue that needs to be triaged by the Pinecone team
Projects
None yet
Development

No branches or pull requests

1 participant