Class ChatKnowledgeBinding
- All Implemented Interfaces:
AutoCloseable
Applications with live corpora create one binding per conversation owner.
Integrations that receive an owner object at dispatch time should use
live(Object, String, String, int, RetrievalEngine.Retriever) so the
exact owner can be verified without treating display names or identifiers as
authority. The owner reference is weak and does not extend the owner's
lifecycle. The retriever receives the complete canonical
RetrievalRequest; no process-global registry or competing result
model is introduced. Provider-backed annotation wiring uses
create(String, RetrievalEngine, RetrievalConfig) with the same
request path.
invalidate() advances an owner-local revision included in every
request cache key. A caller may also supply an application revision in
ChatRetrievalContext; live bindings disable framework caching by
default so appends within one episode cannot return stale evidence.
- Since:
- 0.13.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the owner-scoped engine exactly once.config()Returns the immutable chat retrieval configuration.static ChatKnowledgeBindingcreate(Object exactOwner, String ownerId, RetrievalEngine engine, RetrievalConfig config) Creates a binding that can verify one exact owner object by identity.static ChatKnowledgeBindingcreate(String ownerId, RetrievalEngine engine, RetrievalConfig config) Creates an owner-scoped binding around an existing engine.longAdvances the owner-local source revision used by subsequent cache keys.booleanReturns whether this binding was created for the supplied exact owner.booleanReturns whether no@Knowledgedeclaration backs this binding: whether it was created byundeclared(Object, String, String, int, RetrievalEngine.Retriever).static ChatKnowledgeBindinglive(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates an exact-owner live binding with fail-open, no-cache defaults.static ChatKnowledgeBindinglive(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever, Runnable closeAction) Creates an exact-owner live binding with an idempotent close action.static ChatKnowledgeBindinglive(String ownerId, String sourceName, int topK, KnowledgeBase knowledgeBase) Creates a live binding over aKnowledgeBasethe application owns and keeps mutating.static ChatKnowledgeBindinglive(String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates a live-source binding with fail-open, no-cache chat defaults.static ChatKnowledgeBindinglive(String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever, Runnable closeAction) Creates a live-source binding with an idempotently invoked close action.ownerId()Returns the stable owner identity.retrieve(String query, ChatRetrievalContext context) Retrieves evidence for one outbound chat request.longrevision()Returns the current owner-local revision.Returns the first canonical source name; seeconfig()for all of them.static ChatKnowledgeBindingundeclared(Object exactOwner, String ownerId, String sourceName, int topK, int contextWindow, RetrievalEngine.Retriever retriever) undeclared(Object, String, String, int, RetrievalEngine.Retriever)whose evidence is rendered withincontextWindowestimated tokens instead of the default window ofRetrievalConfig.Builder.static ChatKnowledgeBindingundeclared(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates an exact-owner live binding that no@Knowledgedeclaration backs, with fail-open, no-cache defaults.
-
Method Details
-
create
public static ChatKnowledgeBinding create(String ownerId, RetrievalEngine engine, RetrievalConfig config) Creates an owner-scoped binding around an existing engine.- Parameters:
ownerId- stable conversation-owner identityengine- owner-scoped retrieval engineconfig- chat retrieval configuration naming at least one source- Returns:
- owner-scoped binding
-
create
public static ChatKnowledgeBinding create(Object exactOwner, String ownerId, RetrievalEngine engine, RetrievalConfig config) Creates a binding that can verify one exact owner object by identity.The owner is held weakly.
isOwnedBy(Object)compares object identity rather thanObject.equals(Object)so equal names or identifiers cannot authorize a different owner.- Parameters:
exactOwner- exact conversation owner objectownerId- stable owner identity used in retrieval metadataengine- owner-scoped retrieval engineconfig- chat retrieval configuration naming at least one source- Returns:
- exact-owner-scoped binding
- Since:
- 0.14.0
-
live
public static ChatKnowledgeBinding live(String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates a live-source binding with fail-open, no-cache chat defaults.- Parameters:
ownerId- stable conversation-owner identitysourceName- name of a declared@KnowledgetopK- maximum evidence countretriever- application-owned live retriever- Returns:
- owner-scoped live binding
-
live
public static ChatKnowledgeBinding live(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates an exact-owner live binding with fail-open, no-cache defaults.- Parameters:
exactOwner- exact conversation owner objectownerId- stable owner identity used in retrieval metadatasourceName- name of a declared@KnowledgetopK- maximum evidence countretriever- application-owned live retriever- Returns:
- exact-owner-scoped live binding
- Since:
- 0.14.0
-
live
public static ChatKnowledgeBinding live(String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever, Runnable closeAction) Creates a live-source binding with an idempotently invoked close action.- Parameters:
ownerId- stable conversation-owner identitysourceName- name of a declared@KnowledgetopK- maximum evidence countretriever- application-owned live retrievercloseAction- application resource cleanup- Returns:
- owner-scoped live binding
-
live
public static ChatKnowledgeBinding live(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever, Runnable closeAction) Creates an exact-owner live binding with an idempotent close action.- Parameters:
exactOwner- exact conversation owner objectownerId- stable owner identity used in retrieval metadatasourceName- name of a declared@KnowledgetopK- maximum evidence countretriever- application-owned live retrievercloseAction- application resource cleanup- Returns:
- exact-owner-scoped live binding
- Since:
- 0.14.0
-
undeclared
public static ChatKnowledgeBinding undeclared(Object exactOwner, String ownerId, String sourceName, int topK, RetrievalEngine.Retriever retriever) Creates an exact-owner live binding that no@Knowledgedeclaration backs, with fail-open, no-cache defaults.Such a binding carries knowledge the integration supplies in code, such as an agent's conversation memory. A
ChatTurnsent throughSCOPBridge.sendToLLMin tnsai-integration searches it beside the owner's other bindings, at most one of them declared, as long as no two of them search the same source name. It is checked against its exact owner only, never against the owner's declarations, sosourceNamenames the binding's source rather than a declared entry, and the owner may declare no knowledge at all. Its evidence renders under the source name its retriever gives each result; the binding does not replace it withsourceName.ChatKnowledgeBindingValidatorrefuses it, so an agent, which searches declared knowledge only, does too.With a retrieval context, each send refuses the binding, throwing
IllegalArgumentException, when itssourceNameis the name of any@Knowledgeits owner declares, whatever that knowledge's type or use and whether or not it is enabled; without a retrieval context only the owner is checked. A name of the integration's own, such as one under a prefix no declaration uses, keeps the binding usable for every owner class.The binding has the default context window of
RetrievalConfig.Builder;undeclared(Object, String, String, int, int, RetrievalEngine.Retriever)gives it another. Beside the owner's other bindings each binding's evidence is rendered within its own window, so a turn can carry as many windows of evidence for one owner as the owner has bindings.- Parameters:
exactOwner- exact conversation owner objectownerId- stable owner identity used in retrieval metadatasourceName- source name of the binding, not of its evidencetopK- maximum evidence countretriever- application-owned live retriever- Returns:
- exact-owner-scoped undeclared live binding
- Since:
- 0.18.6
- See Also:
-
undeclared
public static ChatKnowledgeBinding undeclared(Object exactOwner, String ownerId, String sourceName, int topK, int contextWindow, RetrievalEngine.Retriever retriever) undeclared(Object, String, String, int, RetrievalEngine.Retriever)whose evidence is rendered withincontextWindowestimated tokens instead of the default window ofRetrievalConfig.Builder. The window bounds this binding's evidence only: the owner's other bindings keep their own.- Parameters:
exactOwner- exact conversation owner objectownerId- stable owner identity used in retrieval metadatasourceName- source name of the binding, not of its evidencetopK- maximum evidence countcontextWindow- maximum estimated tokens of this binding's evidence in one turn; positiveretriever- application-owned live retriever- Returns:
- exact-owner-scoped undeclared live binding
- Throws:
IllegalArgumentException- ifcontextWindowis not positive- Since:
- 0.18.6
- See Also:
-
live
public static ChatKnowledgeBinding live(String ownerId, String sourceName, int topK, KnowledgeBase knowledgeBase) Creates a live binding over aKnowledgeBasethe application owns and keeps mutating.The binding holds the corpus rather than copying it, so documents added after binding are visible to retrieval. Closing the binding does not close the corpus — that stays the application's to manage, which matters when the same corpus is rebound on every message.
Retrieval is keyword-strategy, fail-open and uncached, matching what
KnowledgeBase.search(String, int)actually does.sourceNameis stamped on every piece of evidence as provenance and must be the name of the agent'sMEMORYchat knowledge, or the agent refuses the binding.- Parameters:
ownerId- stable conversation-owner identitysourceName- declared chat source nametopK- maximum evidence countknowledgeBase- application-owned corpus- Returns:
- owner-scoped live binding over the corpus
- Since:
- 0.16.0
-
ownerId
Returns the stable owner identity. -
isOwnedBy
Returns whether this binding was created for the supplied exact owner.Bindings created without an exact owner always return
false. Identity comparison deliberately ignoresequals, display names, and string identifiers.- Parameters:
owner- candidate conversation owner- Returns:
trueonly for the exact bound owner object- Since:
- 0.14.0
-
isUndeclared
public boolean isUndeclared()Returns whether no@Knowledgedeclaration backs this binding: whether it was created byundeclared(Object, String, String, int, RetrievalEngine.Retriever).- Returns:
trueonly for an undeclared binding- Since:
- 0.18.6
-
sourceName
Returns the first canonical source name; seeconfig()for all of them. -
config
Returns the immutable chat retrieval configuration. -
retrieve
Retrieves evidence for one outbound chat request.The context's
turn message, when present, is searched instead ofquery. It, the conversation identity and the source paths reach the request as its own components, not as metadata filters.- Parameters:
query- the user message the provider renders, searched when the context carries no turn messagecontext- request-local scope and lifecycle context- Returns:
- canonical retrieval result
-
invalidate
public long invalidate()Advances the owner-local source revision used by subsequent cache keys.- Returns:
- the new revision
-
revision
public long revision()Returns the current owner-local revision. -
close
public void close()Closes the owner-scoped engine exactly once.- Specified by:
closein interfaceAutoCloseable
-