Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 28, 2026

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

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

  • Updated unit tests to verify correct API format with type discriminator
  • Updated tests to use as_dict() method name
  • All 16 query class tests pass
  • mypy type checking passes

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 querytext_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.

Written by Cursor Bugbot for commit 50ee953. This will update automatically on new commits. Configure here.

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
@jhamon jhamon added bug Something isn't working python Pull requests that update Python code labels Jan 28, 2026
@jhamon jhamon merged commit 9dcb0ff into fts Jan 28, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/fix-query-classes-api-format branch January 28, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants