Skip to content

API Reference parrot.knowledge.retrieval.policies.vector_seed

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

parrot.knowledge.retrieval.policies.vector_seed

View source

VectorSeedPolicy — hybrid BM25 ∥ dense seeding, fused with RRF.

Spec §5.2, as corrected by OQ-9. T6 seeds over what exists; T6b (durable pgvector/HNSW) is deferred, gated on T13 measuring a real miss — do NOT build that here, and do NOT build a latency gate: the p50 < 120 ms target is provisional (spec §13), since faiss.IndexFlatL2 is an exhaustive scan.

Two legs run concurrently (asyncio.gather) — a sequential seed would double the stage §4.4's escalation cost model assumes is the expensive one:

  • Lexical — SQLiteGraphReader.search_symbols() (FTS5/BM25). Indexes title + summary only, not bodies — this caps recall and is a real limitation, not an oversight.
  • Dense — an embedder exposing async search_similar(query_text, top_k) -> list[tuple[node_id, distance]] (the shape GraphIndexEmbedder.search_similar has, spec §14.2) over the in-process faiss.IndexFlatL2.

Fused with the existing HybridPageIndexSearch._rrf_fuse formula (pageindex/hybrid_search.py:277) — reused verbatim, not reinvented.

Alias ContextBundle

Re-exported from parrot.knowledge.retrieval.models.ContextBundle.

Alias ContextUnit

Re-exported from parrot.knowledge.retrieval.models.ContextUnit.

Alias DerivedSymbolIndex

Re-exported from parrot.knowledge.retrieval.symbols.DerivedSymbolIndex.

Alias EdgeKind

Re-exported from parrot.knowledge.graphindex.schema.EdgeKind.

Alias EdgeRef

Re-exported from parrot.knowledge.retrieval.models.EdgeRef.

Alias Evidence

Re-exported from parrot.knowledge.retrieval.models.Evidence.

Alias EvidenceOrigin

Re-exported from parrot.knowledge.retrieval.models.EvidenceOrigin.

Alias HybridPageIndexSearch

Re-exported from parrot.knowledge.pageindex.hybrid_search.HybridPageIndexSearch.

Alias NodeKind

Re-exported from parrot.knowledge.graphindex.schema.NodeKind.

Alias NodeRef

Re-exported from parrot.knowledge.retrieval.models.NodeRef.

Alias RetrievalBudget

Re-exported from parrot.knowledge.retrieval.models.RetrievalBudget.

Alias RetrievalRequest

Re-exported from parrot.knowledge.retrieval.models.RetrievalRequest.

Alias Seed

Re-exported from parrot.knowledge.retrieval.policies.base.Seed.

Alias Subgraph

Re-exported from parrot.knowledge.retrieval.policies.base.Subgraph.

Alias UniversalNode

Re-exported from parrot.knowledge.graphindex.schema.UniversalNode.

Class VectorSeedPolicy

Hybrid BM25 ∥ dense seeding, fused with RRF; expand is depth-1 CONTAINS.

Fields:

Field Type Default Description
kind Literal['vector_seed'] 'vector_seed' Discriminator for the future RetrievalPolicy union (spec §5.0).
symbols DerivedSymbolIndex The DerivedSymbolIndex for qualname derivation.
reader Any | None An object exposing SQLiteGraphReader's search_symbols/ get_node/children methods (an already-load()ed SQLiteGraphReader in production), or None when the workspace's backend has no lexical leg (e.g. an ArangoDB-backed workspace — FTS5 exists only on SQLite). Typed loosely (not SQLiteGraphReader directly, same rationale as embedder) so a lightweight test double can stand in.
supports_fts bool True Whether reader (when present) actually has a usable nodes_fts table. False degrades to dense-only even when reader is present (e.g. reader kept only for node-metadata lookups on a backend without FTS5).
embedder Any | None None An object exposing async search_similar(query_text, top_k) -> list[tuple[str, float]] (the shape GraphIndexEmbedder has) — None when no dense leg is available. Typed loosely (not GraphIndexEmbedder directly) so a lightweight test double can stand in without pulling in a real embedding model.
node_id_by_qualname dict[tuple[str, str], str] (path, qualname) -> node_id, built by build_node_id_index — same bridge DirectSymbolPolicy uses.
repo str Repository name this policy serves.
rev str Concrete git SHA this policy's symbols/reader were built at — typically WorkspacePin.rev_of(repo). Search results carry no rev of their own, so it is stamped here (mirroring how DirectSymbolPolicy gets it implicitly via seed NodeRefs already produced by a rev-scoped DerivedSymbolIndex).
repo_path Path Local filesystem working-tree path, for read_at_rev.

Method VectorSeedPolicy.seed

Seed via BM25 ∥ dense, fused with RRF. Degrades gracefully.

Runs both legs concurrently via asyncio.gather — never sequentially. If only one leg is available, that leg alone is used (no failure).

seed(req: RetrievalRequest, graph: Any = None, *, top_k: int = 20) -> tuple[Seed, ...]

Parameter Type Default Description
req RetrievalRequest The retrieval request.
graph Any None Unused (reader/embedder are bound on self).
top_k int 20 Maximum results per leg, and of the fused output.

Returns: tuple[Seed, ...] — Fused Seeds, best-first by RRF score.

Method VectorSeedPolicy.expand

Expand each seed one hop over EdgeKind.CONTAINS only.

expand(seeds: tuple[Seed, ...], graph: Any, budget: RetrievalBudget) -> Subgraph

Parameter Type Default Description
seeds tuple[Seed, ...] Seed anchors from seed.
graph Any Unused (the reader is bound on self).
budget RetrievalBudget The request's RetrievalBudget.

Returns: Subgraph — A Subgraph of every seed plus its depth-1 CONTAINS children.

Method VectorSeedPolicy.prune

Trim to budget.max_expansion_nodes — budget trim only.

prune(subgraph: Subgraph, budget: RetrievalBudget) -> Subgraph

Parameter Type Default Description
subgraph Subgraph The Subgraph from expand.
budget RetrievalBudget The request's RetrievalBudget.

Returns: Subgraph — subgraph, trimmed if it exceeds budget.max_expansion_nodes.

Method VectorSeedPolicy.assemble

Read content at the pinned rev and build the ContextBundle.

assemble(subgraph: Subgraph, budget: RetrievalBudget) -> ContextBundle

Parameter Type Default Description
subgraph Subgraph The (pruned) Subgraph to assemble.
budget RetrievalBudget The request's RetrievalBudget.

Returns: ContextBundle — The final ContextBundle.

Alias derive_digest

Re-exported from parrot.knowledge.retrieval.digest.derive_digest.

Attribute logger

Alias read_at_rev

Re-exported from parrot.knowledge.retrieval.pin.read_at_rev.

Alias read_file_sha1

Re-exported from parrot.knowledge.retrieval.policies.direct_symbol.read_file_sha1.

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