Interface SourceLoader
- All Known Implementing Classes:
HttpKnowledgeSourceLoader,LocalFileSourceLoader
KnowledgeSourceConfig declaration into
the per-Role RAG memory store at binding-init time.
One SourceLoader implementation per
Knowledge.Type. TnsAI bundles FILE and HTTP/HTTPS
URL loaders. DATABASE remains an application-provided SPI extension. No
loader serves MEMORY or GRAPH, which load nothing; discovering one fails.
Note what this seam can and cannot express. load(com.tnsai.rag.KnowledgeSourceConfig) runs
once, when a Role's binding is built, and returns the documents it
found; the framework indexes those and searches the index thereafter. A
corpus that must be queried per request — a remote vector database, a search
API — therefore cannot be a SourceLoader at all, no matter what the
annotation offers to configure it with. Those are served by
com.tnsai.rag.RetrievalEngineProvider, which is invoked per
retrieval rather than per binding.
Loaders are looked up by handles() at binding-init time. A
declared source whose type has no registered loader is skipped with a
warning, and the binding still builds from whichever sources did load;
only when every enabled source is unloadable does binding fail.
The line is drawn there so that installing one optional loader at a time
stays possible — but it does mean a missing loader costs part of the
corpus without failing anything, so read the warning.
- Since:
- 0.5.4 (issue #172, Phase 1)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordOne document loaded by aSourceLoader— the unit ingested into the vector store. -
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.annotations.Knowledge.Typehandles()TheKnowledge.Typethis loader handles.load(com.tnsai.rag.KnowledgeSourceConfig source) Loads documents from the given source declaration.metadata(com.tnsai.rag.KnowledgeSourceConfig source, SourceLoader.LoadedDocument document) Returns optional metadata for one loaded document.
-
Method Details
-
handles
com.tnsai.annotations.Knowledge.Type handles()TheKnowledge.Typethis loader handles.RoleRagBindingroutes each declared source to the loader whosehandles()matches.- Returns:
- the supported type
-
load
Loads documents from the given source declaration.Each returned
SourceLoader.LoadedDocumentcarries anid(used as the entry id in the vector store), the textualcontent, and an optionalsourcelabel for retrieval-time attribution (e.g. the file path, URL, or DB row id).The return type is a list because a loader decides the unit of retrieval: it may split one source into as many documents as it likes, and everything downstream —
topK,minScore,dedupeThreshold,contextWindow— is defined over whatever it returns. The bundledLocalFileSourceLoaderkeeps small files intact and emits stable, format-aware chunks for larger files (TAN-5327).Successfully loaded empty sources return an empty list. The bundled FILE and HTTP loaders throw
RetrievalExceptionwith reasonSOURCE_LOADINGwhen a source cannot be read; they never publish a partial corpus as an empty success. Invalid source configuration and content surface asCONFIGURATIONat the binding boundary.The returned list defines ingest order. Ordered consumers observe documents in exactly this order, so implementations must return a deterministic list for a stable source snapshot.
- Parameters:
source- the normalized knowledge-source declaration- Returns:
- loaded documents in deterministic ingest order, or empty when the source was successfully read but contained no documents
-
metadata
default Map<String,String> metadata(com.tnsai.rag.KnowledgeSourceConfig source, SourceLoader.LoadedDocument document) Returns optional metadata for one loaded document.The default implementation lets loaders opt out of document metadata. Hierarchical loaders can declare relationships with
HierarchyMetadata.PARENT_ID; binding-owned metadata such as the source fence is added byRoleRagBinding. Temporal loaders provideTemporalMetadata.TIMESTAMPas a canonical ISO-8601 instant such as2026-07-26T00:00:00Z.- Parameters:
source- the normalized declaration that produced the documentdocument- one document returned fromload(KnowledgeSourceConfig)- Returns:
- document metadata, or an empty map
- Since:
- 0.13.0
-