Skip to content

symfonic.knowledge.models

models

Data models for the knowledge retrieval layer.

KnowledgeFragment is the canonical return type for all KnowledgeProvider implementations. It is frozen so callers can cache and hash results safely.

KnowledgeFragment dataclass

KnowledgeFragment(
    content: str,
    source: str,
    score: float,
    metadata: dict[str, Any] = dict(),
)

A single piece of retrieved knowledge with source attribution.

Returned by every KnowledgeProvider.search() call. The score is always a cosine-similarity-derived value in [0.0, 1.0] where higher means more relevant.

content instance-attribute

content: str

The raw text of the retrieved document chunk.

metadata class-attribute instance-attribute

metadata: dict[str, Any] = field(default_factory=dict)

Arbitrary key-value metadata from the underlying store.

score instance-attribute

score: float

Similarity score in [0.0, 1.0]; higher is more relevant.

source instance-attribute

source: str

Human-readable source reference, e.g. 'LFT Art. 47' or 'RFC 7231 §5.3'.

format_citation

format_citation() -> str

Return a formatted citation string for prompt injection.

Example::

SOURCE [RFC 7231 §5.3]: Accept header field specifies acceptable...
Source code in src/symfonic/knowledge/models.py
def format_citation(self) -> str:
    """Return a formatted citation string for prompt injection.

    Example::

        SOURCE [RFC 7231 §5.3]: Accept header field specifies acceptable...
    """
    return f"SOURCE [{self.source}]: {self.content}"