-
Notifications
You must be signed in to change notification settings - Fork 114
feat: add TextQuery and VectorQuery classes #586
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
Conversation
Add query model classes for the document search API: - TextQuery: for full-text search with field, query, boost, slop - VectorQuery: for vector search with field, values, sparse_values Both classes support dict-like access and serialize to API format. Closes SDK-108
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
|
||
| :returns: Dictionary representation for the API. | ||
| """ | ||
| result: dict = {"field": self.field, "query": self.query} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextQuery.to_dict() uses wrong API field name
High Severity
The to_dict() method serializes the query string with key "query", but the Pinecone API expects "text_query" as shown in the OpenAPI-generated model at pinecone/core/openapi/db_data/model/text_query.py. This mismatch will cause API requests using TextQuery as the score_by parameter to fail or produce unexpected results because the server won't recognize the query text.
| result["boost"] = self.boost | ||
| if self.slop is not None: | ||
| result["slop"] = self.slop | ||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextQuery.to_dict() missing required type discriminator field
High Severity
The to_dict() methods in TextQuery and VectorQuery omit the required type discriminator field. The Pinecone API uses this field (e.g., 'text', 'vector') to correctly identify the query type within the score_by parameter, so its absence prevents proper API interpretation.
Additional Locations (1)
| boost: float | None = None | ||
| slop: int | None = None | ||
|
|
||
| def to_dict(self) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent method naming with similar query classes
Low Severity
The new TextQuery and VectorQuery classes use to_dict() for serialization, while semantically similar query classes in the same module (SearchQuery, SearchQueryVector, SearchRerank) all use as_dict(). This naming inconsistency within the query-related classes could confuse developers expecting a uniform API.
Additional Locations (1)
Address unresolved review comments from PR #586: - Fix TextQuery: use "text_query" instead of "query" for API field name - Add required "type" discriminator field ("text" / "vector") - Rename to_dict() to as_dict() for consistency with SearchQuery classes
## Summary Fixes unresolved review comments from PR #586 that were merged without being addressed. **Related PR:** #586 ## Problems Fixed ### 1. Wrong API field name in `TextQuery` (High Severity) The `as_dict()` method was serializing the query string with key `"query"`, but the Pinecone API expects `"text_query"` as defined in the OpenAPI spec. ### 2. Missing `type` discriminator field (High Severity) Both `TextQuery` and `VectorQuery` were missing the required `type` discriminator field used by the `ScoreByQuery` oneOf schema: - `TextQuery` → `"type": "text"` - `VectorQuery` → `"type": "vector"` ### 3. Inconsistent method naming (Low Severity) Changed `to_dict()` to `as_dict()` for consistency with similar search-related classes (`SearchQuery`, `SearchQueryVector`, `SearchRerank`). ## Breaking Changes Since these classes were just added in PR #586 and haven't been released yet, these changes should not affect any users: - `TextQuery.to_dict()` → `TextQuery.as_dict()` - `VectorQuery.to_dict()` → `VectorQuery.as_dict()` ## Usage Example ```python from pinecone import TextQuery, VectorQuery # TextQuery for full-text search text_query = TextQuery(field="title", query="pink panther") text_query.as_dict() # Returns: {"type": "text", "field": "title", "text_query": "pink panther"} # With optional parameters text_query = TextQuery(field="title", query="pink panther", boost=2.0, slop=1) text_query.as_dict() # Returns: {"type": "text", "field": "title", "text_query": "pink panther", "boost": 2.0, "slop": 1} # VectorQuery for similarity search vector_query = VectorQuery(field="embedding", values=[0.1, 0.2, 0.3]) vector_query.as_dict() # Returns: {"type": "vector", "field": "embedding", "values": [0.1, 0.2, 0.3]} # Use with search_documents() results = index.search_documents( namespace="movies", score_by=TextQuery(field="title", query="pink panther"), top_k=10, ) ``` ## Test Plan - [x] Updated unit tests to verify correct API format with `type` discriminator - [x] Updated tests to use `as_dict()` method name - [x] All 16 query class tests pass - [x] mypy type checking passes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Medium risk because it changes the serialized request shape and renames a public method (`to_dict()` → `as_dict()`), which can break any existing callers even though the change is localized. > > **Overview** > Fixes `TextQuery` and `VectorQuery` API serialization used by `score_by` by adding the required `type` discriminator (`"text"`/`"vector"`) and aligning field names (notably `query` → `text_query` for text scoring). > > Renames the serialization helper from `to_dict()` to `as_dict()` on both classes and updates unit tests to assert the new payload format and method name. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 50ee953. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Summary
Add query model classes for the document search API.
Closes SDK-108
Classes
TextQueryfield,query,boost,slopVectorQueryfield,values,sparse_valuesBoth classes:
query["field"])to_dict()score_byparameter insearch_documents()Usage Example
Test Plan
Note
Low Risk
Low risk: adds new lightweight dataclass helpers and exports plus unit tests, without changing existing request/response handling or core search logic.
Overview
Adds new
TextQueryandVectorQuerydataclasses to representsearch_documents()score_byinputs, including optional parameters andto_dict()serialization (andDictLikeaccess via the existing base).Exports these types via
pinecone.db_data.dataclassesand top-level lazy imports inpinecone/__init__.py, and adds unit tests validating serialization and dict-like behavior.Written by Cursor Bugbot for commit f963847. This will update automatically on new commits. Configure here.