Skip to content

API Reference parrot.stores.parents.in_table

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.stores.parents.in_table

View source

In-table parent searcher for pgvector stores.

This module implements :class:InTableParentSearcher, the default AbstractParentSearcher for deployments that store both chunks and their parent documents in the same vector table (postgres / pgvector).

Implementation approach (Approach A — direct connection access):

The searcher uses the store's session() async context manager and issues a single parameterised SQL query per fetch() call. This avoids the N+1 pattern that would arise from fetching each parent individually.

The SQL semantics are:

.. code-block:: sql

SELECT <id_col>, <doc_col>, <meta_col>
FROM <schema>.<table>
WHERE <id_col> = ANY(:ids)
  AND (
    (<meta_col>->>'is_full_document')::boolean = true
    OR <meta_col>->>'document_type' = 'parent_chunk'
  )

This single round trip covers both 2-level parents (is_full_document=True) and 3-level intermediate parent chunks (document_type='parent_chunk').

Alias AbstractParentSearcher

Re-exported from parrot.stores.parents.abstract.AbstractParentSearcher.

Alias AbstractStore

Re-exported from parrot.stores.abstract.AbstractStore.

Alias Document

Re-exported from parrot.stores.models.Document.

Class InTableParentSearcher

Fetch parents from the same vector table by metadata filter.

Default implementation for postgres / pgvector. Issues a single SQL query per :meth:fetch call regardless of how many parent IDs are requested — no N+1.

Implementation: Approach A (direct connection access). Uses the store's session() async context manager to issue a raw parameterised SELECT. The parent filter covers both legacy is_full_document=True parents and the new document_type='parent_chunk' intermediate parents introduced by FEAT-128.

Parameter Type Default Description
store AbstractStore An :class:~parrot.stores.abstract.AbstractStore instance. The store MUST expose a session() async context manager (as implemented by :class:~parrot.stores.postgres.PgVectorStore).

Method InTableParentSearcher.fetch

Fetch parent documents by ID in a single SQL round trip.

fetch(parent_ids: List[str]) -> Dict[str, Document]

Parameter Type Default Description
parent_ids List[str] List of parent document IDs to retrieve. An empty list returns an empty dict immediately (no DB call).

Returns: Dict[str, Document] — Mapping of {parent_document_id: Document} containing only rows whose metadata marks them as parents (is_full_document=True OR document_type='parent_chunk'). IDs that are not found or are not parent rows are simply absent.

Raises:

  • Exception — Only for infrastructure failures (DB connection errors, SQL errors). Individual misses are silently omitted.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally