Skip to content

Conversation

@jhamon
Copy link
Collaborator

@jhamon jhamon commented Jan 30, 2026

Summary

This PR adds response model classes for the document search API, enabling a clean and intuitive interface for working with search results.

  • Document class: Represents a document returned from search with id, score, and dynamic field access
  • DocumentSearchResponse class: Wraps the list of documents with usage information

Problem

The document search API needs response models that allow users to easily access search results. Documents can have dynamic fields (varying per index schema), so the Document class needs to support flexible field access patterns.

Solution

The Document class provides three ways to access fields:

# Attribute access
doc.title  # "The Pink Panther"

# Dict-style access
doc["title"]  # "The Pink Panther"

# Safe get with default
doc.get("title", "N/A")  # "The Pink Panther"
doc.get("missing", "Unknown")  # "Unknown"

The class also supports:

  • Standard id and score properties
  • keys(), values(), items() for iteration
  • in operator for field existence checks
  • to_dict() for serialization
  • Equality comparison

Usage Example

from pinecone import Pinecone, text_query

pc = Pinecone()
index = pc.Index("movies")

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

for doc in results.documents:
    print(f"{doc.id}: {doc.score}")
    print(f"  Title: {doc.title}")
    print(f"  Year: {doc.get('year', 'Unknown')}")

Test Plan

  • Unit tests for attribute access to dynamic fields
  • Unit tests for dict-style access (doc["field"])
  • Unit tests for safe get() with default values
  • Unit tests for DocumentSearchResponse wrapper
  • Unit tests for edge cases (missing fields, equality, repr)
  • mypy type checking passes
  • All 31 new tests pass

Related

  • Linear: SDK-110
  • Depends on: PR#11 (Query factory functions - text_query, vector_query)

Note

Low Risk
Low risk: this is additive (new dataclasses + exports) with unit tests; primary impact is new public API surface and lazy-import wiring.

Overview
Adds document-search response models. Introduces Document (supports id/score plus dynamic fields via attribute access, [], and get()) and DocumentSearchResponse (wraps documents, optional usage, and _response_info).

Exposes these types through pinecone.db_data.dataclasses and top-level pinecone lazy imports, and adds unit tests covering field access patterns, dict-like behavior, equality/serialization, and basic response usage.

Written by Cursor Bugbot for commit 64ab854. 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
…arch API

Add response model classes for the document search API:

- Document class with id, score, and dynamic field access via attribute,
  dict-style, and safe get() methods
- DocumentSearchResponse class wrapping documents list with usage info
- Unit tests for all access patterns and edge cases
- Export classes via lazy imports in pinecone module

Closes SDK-110
@jhamon jhamon added the enhancement New feature or request label Jan 30, 2026
@jhamon jhamon merged commit 4968fd8 into fts Jan 30, 2026
7 checks passed
@jhamon jhamon deleted the jhamon/sdk-110-document-response-models branch January 30, 2026 18:51
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.

2 participants