Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 30, 2026

Summary

Adds text_query() and vector_query() factory functions that provide a simpler, more ergonomic API for constructing query objects to use with search_documents().

Problem

Users need to import and instantiate TextQuery and VectorQuery classes directly, which is verbose for simple use cases.

Solution

Added two factory functions that wrap the dataclass constructors:

  • text_query(field, query, boost=None, slop=None) - Creates a TextQuery for full-text search
  • vector_query(field, values=None, sparse_values=None) - Creates a VectorQuery for similarity search

Both functions are exported from the pinecone package for convenient imports.

Usage Examples

from pinecone import text_query, vector_query, SparseValues

# Simple text search
results = index.search_documents(
    namespace="movies",
    score_by=text_query("title", "pink panther"),
    top_k=10,
)

# Phrase match with quotes
results = index.search_documents(
    namespace="movies",
    score_by=text_query("title", '"pink panther"'),
    top_k=10,
)

# With boost and slop
results = index.search_documents(
    namespace="movies",
    score_by=text_query("title", '"pink panther"', boost=3.0, slop=2),
    top_k=10,
)

# Dense vector search
results = index.search_documents(
    namespace="movies",
    score_by=vector_query("embedding", values=[0.1, 0.2, 0.3]),
    top_k=10,
)

# Sparse vector search
results = index.search_documents(
    namespace="movies",
    score_by=vector_query(
        "sparse_embedding",
        sparse_values=SparseValues(indices=[1, 5, 10], values=[0.5, 0.3, 0.2]),
    ),
    top_k=10,
)

Related Issues


Note

Low Risk
Low risk: adds thin wrapper factory functions and exposes them via top-level lazy imports, with unit coverage; main impact is expanded public API surface and import/export behavior.

Overview
Adds new factory helpers text_query() and vector_query() (in pinecone/db_data/query_helpers.py) to simplify constructing TextQuery/VectorQuery objects for search_documents().

Exports these helpers from the top-level pinecone package via the existing lazy-import mechanism, and adds unit tests validating parameter handling and .as_dict() serialization plus top-level importability.

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

Add factory functions that provide a simpler API for constructing query
objects to use with search_documents():

- text_query(field, query, boost=None, slop=None) - Creates a TextQuery
- vector_query(field, values=None, sparse_values=None) - Creates a VectorQuery

Both functions are exported from the pinecone package for convenient imports.

Linear: SDK-109
@jhamon jhamon added the enhancement New feature or request label Jan 30, 2026
@jhamon jhamon merged commit 3703df1 into fts Jan 30, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/sdk-109-query-factory-functions-text_query-vector_query branch January 30, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant