symfonic.knowledge.protocols¶
protocols ¶
Protocol interfaces for the knowledge retrieval layer.
KnowledgeProvider is the single abstract interface that all RAG adapters must satisfy. Implementations can connect to ChromaDB, Pinecone, Qdrant, or any other vector store.
Architecture note: the protocol is @runtime_checkable so that adapters can be validated with isinstance() without requiring explicit inheritance.
Layering note (TA2.4): this module is the declared port of the knowledge
capability -- T4.2.1's integration-adapter catalogue names
symfonic.knowledge.protocols.KnowledgeProvider as the port
symfonic.knowledge.adapters.chroma implements. The dependency matrix's
integration row licenses "exactly the protocol module it implements and the
contract types those protocols reference", and archcheck recognises a
port only by module basename, so KnowledgeFragment is re-exported here
rather than reached for in .models. There is one definition; this is the
port surface naming it.
KnowledgeFragment
dataclass
¶
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.
metadata
class-attribute
instance-attribute
¶
Arbitrary key-value metadata from the underlying store.
source
instance-attribute
¶
Human-readable source reference, e.g. 'LFT Art. 47' or 'RFC 7231 §5.3'.
format_citation ¶
Return a formatted citation string for prompt injection.
Example::
SOURCE [RFC 7231 §5.3]: Accept header field specifies acceptable...
KnowledgeProvider ¶
Bases: Protocol
Abstract interface for semantic knowledge retrieval (RAG).
Concrete implementations connect to vector databases (ChromaDB, Pinecone, Qdrant, etc.) and return scored knowledge fragments.
All methods are async. Synchronous backends must wrap blocking calls
with asyncio.to_thread.
collection_info
async
¶
Return metadata about the connected collection.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with at least |
search
async
¶
Search for knowledge fragments matching the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
Natural language search query. |
required |
limit
|
int
|
Maximum number of fragments to return. |
3
|
Returns:
| Type | Description |
|---|---|
list[KnowledgeFragment]
|
List of KnowledgeFragment sorted by descending score. |