Package com.tnsai.rag
package com.tnsai.rag
Canonical RAG configuration and retrieval contracts.
Ownership
tnsai-coreowns immutable configuration, request/result, lifecycle, and provider contracts.tnsai-intelligenceowns source loaders, strategy execution, ranking, reranking, deduplication, and cache implementations.- Chat and action entry points own prompt/context rendering. The engine
never emits
<tnsai-memory>or_rag_contextcontent. ConsequentlySearch.contextWindow()is a rendering budget owned by the caller, not the engine — see the invariant below.
Runtime invariants
- An engine is created from one owner's canonical
KnowledgeSourceConfigset and closed with that owner. - Every cache key and backend namespace includes the complete
RetrievalScopeand the request's metadata filters; query-only or source-only global caches are forbidden. SeeRetrievalRequest.metadataFilters()for the digest rules a key must follow. - The engine neither validates nor applies
Search.contextWindow(). It bounds assembled prompt text, and the engine returnsRetrievalEvidencerather than prompt text, so there is nothing for it to bound. Ordinary retrieval evidence volume is governed bytopK,topN, andminScore. Whichever entry point renders evidence into a prompt appliescontextWindowthere and reports truncation through its own channel — on the action path,RetrievalSpi.RETRIEVED_CONTEXT_TRUNCATED_KEY. An engine-path caller that never renders evidence into a prompt therefore has no window to enforce. use = DIRECTknowledge is an action and chat-turn policy, not an engine one. Each DIRECT entry is given whole within itsmaxTokens, or a quarter of the model's input window, and a source over that budget fails rather than being truncated. DIRECT bypasses query ranking but retains source admission, exact metadata filters, configuration/provider checks, and request cancellation.- Providers check cooperative cancellation and absolute deadlines between blocking phases and configure backend-native timeouts.
- Empty evidence is a successful result. Failures are never encoded as empty evidence or swallowed.
- Evidence retains source, document, score, rank, and strategy provenance through all ranking and formatting phases.
-
ClassDescriptionOwner-scoped binding between chat grounding and one canonical retrieval engine source.The one rule a chat knowledge binding must meet before it grounds a conversation, whoever installs it: an agent, its builder or an integration.The DIRECT part of an agent's chat knowledge, given fresh on every chat turn.One turn's blocks, split at the first SEARCH entry.Optional bridge from a canonical source configuration to the chat-level
KnowledgeBasecontract.Typed, request-local identity and lifecycle context for chat retrieval.Builder for optional, request-local chat context.Opt-in ingest-time transform that prepends chunk context before embedding and BM25 indexing.SPI for LLM-written chunk context used byChunkContext.LLM.Extracts one detected document into TnsAI's normalized ingestion model.Deterministic registry of installedContentExtractorproviders.One structurally addressable block within an extracted document.Canonical content format for a file-backed knowledge source.Immutable byte input passed to aContentExtractorafter detection.Typed failure for document detection, extraction, and chunking.Stable stages across the document-ingestion pipeline.Normalized, provenance-preserving output of aContentExtractor.Immutable declaration context supplied to document extractors.Stable SHA-256 of the ingestion pipeline that produced one indexed file.Portable include/exclude globs for FILE knowledge-source candidates.The one reader ofKnowledgedeclarations.One declared knowledge source together with how a scope uses it.Explicit lifetime for source snapshots shared by retrieval and ordered knowledge consumption.One thread-bound hold on the scope's resources.The knowledge one scope sees: an action's named sources, or a chat turn's whole agent knowledge.Immutable runtime configuration for one RAG knowledge source.Builder retaining the annotation defaults.How one ingested file becomes retrieval documents.Signals that a knowledge-unit policy has no semantics for a document format.What one knowledge source gave a chat turn or an action call.Splits normalized documents and source files into stable retrieval units.One stable retrieval unit.Immutable runtime configuration for action-level retrieval.Builder starting from the framework defaults.Entry-point-neutral diagnostics emitted by a retrieval engine.Cache behavior visible to callers and observability integrations.Agent-scoped retrieval engine shared by chat and action entry points.Backend operation implemented by the intelligence runtime.SPI for creating agent-scopedRetrievalEngineinstances.Immutable evidence returned by aRetrievalEngine.Stable provenance required for audit, citation, and diagnostics.Typed failure raised by the common retrieval runtime.Stable failure categories shared by chat and action entry points.Entry-point-neutral request passed to aRetrievalEngine.Builder with safe defaults for unscoped, non-cancellable retrieval.Immutable outcome returned by aRetrievalEngine.Tenant and session identity carried by a retrieval request.Service Provider Interface for knowledge-context injection at action-dispatch time.Renders retrieved documents behind a single, explicit untrusted-context boundary.The search settings one knowledge entry contributes to its scope: a partial, immutable value holding only theSearchmembers that were given.BuildsSearchSettings; a member not set is not given.Immutable runtime configuration for ordered knowledge-unit consumption.Builder twin for programmatic declarations.Builds and selectsstructural paths.