Skip to content

API Reference parrot.knowledge.retrieval.features

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

parrot.knowledge.retrieval.features

View source

QueryFeatures extractor — pure, sub-millisecond feature extraction.

Spec §4.2. The classifier's design principle: it must never be the thing that costs latency. extract_features is a pure function — no I/O, no LLM call, no clock (INV-3) — over cheap lexical markers (MarkerLexicon) and the in-process DerivedSymbolIndex (TASK-2276, replacing the symbol trie §4.2 originally — and incorrectly — assumed already existed).

Alias DEFAULT_COMPILED_LEXICON

Re-exported from parrot.knowledge.retrieval.lexicon.DEFAULT_COMPILED_LEXICON.

Alias DerivedSymbolIndex

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

Alias Interrogative

Re-exported from parrot.knowledge.retrieval.lexicon.Interrogative.

Alias NodeRef

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

Class QueryFeatures

Pure, cheap features extracted from a query (spec §4.2).

Fields:

Field Type Default Description
resolved_symbols tuple[NodeRef, ...] Distinct NodeRefs resolved from code-literal tokens in the query, via DerivedSymbolIndex — exact hits in the derived symbol index (TASK-2276), never a fuzzy/embedding match.
anchor_count int Number of distinct resolved anchors — ambiguity (multiple candidates per token) is NOT collapsed, so this can legitimately exceed the number of code-literal tokens.
has_relational_verb bool A relational marker (calls/uses/imports/..., quién llama/usa/..., §4.2) was found.
has_causal_marker bool A causal marker (why/por qué/razón/...) was found.
has_aggregation_marker bool An aggregation marker (overview/cómo funciona/..., or the "how does ... work" template) was found.
has_code_literal bool A backtick span, snake_case, CamelCase, or dotted path was found in the raw query text.
token_count int Whitespace-delimited token count of the raw query.
interrogative Interrogative Which interrogative the query opens with, if any — see Interrogative. First-match-wins over MarkerLexicon.interrogative_groups's priority order.

Function extract_features

Extract QueryFeatures from query (INV-3: pure — no I/O, no clock).

extract_features(query: str, symbols: DerivedSymbolIndex) -> QueryFeatures

Parameter Type Default Description
query str The natural-language query text.
symbols DerivedSymbolIndex The DerivedSymbolIndex to resolve code-literal tokens against (in-process lookup only — no I/O).

Returns: QueryFeatures — The extracted, deterministic QueryFeatures.

Attribute logger

Alias normalize_text

Re-exported from parrot.knowledge.retrieval.lexicon.normalize_text.

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