Skip to content
3 min read · 634 words

Class: Retrievable

Defined in: lib/classes/retrievable.ts:134

An immutable, validated retrieved record (RAG content) held by the agent.

Remarks

Peer of @nhtio/adk!Memory / Message / Thought / ToolCall. Carries an explicit trustTier that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that produced the record is the only party that knows its provenance — batteries MUST NOT auto-classify or infer the tier from source.

Constructors

Constructor

ts
new Retrievable(raw: RawRetrievable): Retrievable;

Defined in: lib/classes/retrievable.ts:188

Parameters

ParameterTypeDescription
rawRawRetrievableThe raw retrievable input validated against rawRetrievableSchema.

Returns

Retrievable

Throws

@nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE when raw does not satisfy the schema.

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
contentreadonly| Tokenizable | SpooledArtifactundefinedThe retrieved content: a @nhtio/adk!Tokenizable (inline text) or a @nhtio/adk!SpooledArtifact (reader-backed, large text living in a consumer store). Use Retrievable.estimateTokens for budgeting and Retrievable.contentString to materialise the body at render time.lib/classes/retrievable.ts:161
createdAtreadonlyDateTimeundefinedWhen the source record was created.lib/classes/retrievable.ts:171
idreadonlystringundefinedStable unique identifier for this retrieved record.lib/classes/retrievable.ts:154
kindreadonlystring | undefinedundefinedOptional semantic label.lib/classes/retrievable.ts:167
scorereadonlynumber | undefinedundefinedOptional relevance / similarity score in [0, 1].lib/classes/retrievable.ts:169
sourcereadonlystring | undefinedundefinedOptional provenance string.lib/classes/retrievable.ts:165
trustTierreadonlyRetrievableTrustTierundefinedTrust tier declared by the retrieval middleware.lib/classes/retrievable.ts:163
updatedAtreadonlyDateTimeundefinedWhen the source record was last modified.lib/classes/retrievable.ts:173
schemastaticObjectSchema<RawRetrievable>rawRetrievableSchemaValidator schema that accepts a RawRetrievable object. Remarks Reusable fragment for any schema that needs to validate or nest a retrievable record.lib/classes/retrievable.ts:141

Methods

contentString()

ts
contentString(): Promise<string>;

Defined in: lib/classes/retrievable.ts:283

Returns the content body as a single string.

Returns

Promise<string>

The full content body as a string.

Remarks

For a @nhtio/adk!Tokenizable this is synchronous in effect (resolved immediately); for a @nhtio/adk!SpooledArtifact it reads the full body from the backing store via @nhtio/adk!SpooledArtifact.asString. Always returns a Promise so callers have one code path; render helpers await it at the point the trust-tier envelope is built.


estimateTokens()

ts
estimateTokens(encoding:
  | "gpt2"
  | "r50k_base"
  | "p50k_base"
  | "p50k_edit"
  | "cl100k_base"
  | "o200k_base"
  | "gemini"
  | "llama2"
| "claude"): number | Promise<number>;

Defined in: lib/classes/retrievable.ts:268

Estimates the token count of the content under encoding.

Parameters

ParameterTypeDescription
encoding| "gpt2" | "r50k_base" | "p50k_base" | "p50k_edit" | "cl100k_base" | "o200k_base" | "gemini" | "llama2" | "claude"The encoding identifier to use for counting.

Returns

number | Promise<number>

The estimated token count.

Remarks

Delegates to the content's own estimateTokens: synchronous for a @nhtio/adk!Tokenizable (returns number), asynchronous for a @nhtio/adk!SpooledArtifact (returns Promise<number>, reading the bytes from the backing store on demand). Both shapes satisfy the adapter's token-budget path, which already awaits estimates.

Note: the SpooledArtifact branch materialises the full decoded string transiently to count tokens — reader-backing keeps the body off the permanent heap, but does not eliminate the transient allocation at budgeting time.


isRetrievable()

ts
static isRetrievable(value: unknown): value is Retrievable;

Defined in: lib/classes/retrievable.ts:149

Returns true if value is a Retrievable instance.

Parameters

ParameterType
valueunknown

Returns

value is Retrievable

Remarks

Uses @nhtio/adk!isInstanceOf for cross-realm safety.