@mastra/core
Version:
58 lines • 3.18 kB
TypeScript
import type { KnowledgeNote, KnowledgePage } from '../storage/domains/knowledge/index.js';
import type { MastraEmbeddingModel, MastraEmbeddingOptions, MastraVector } from '../vector/index.js';
/**
* Most chunks one page is embedded as (about 200k estimated tokens of body). Past it the rest of
* the body is found by keyword search only. Bounded so a rewrite can drop the old chunks by id,
* which every vector store supports, without knowing how many there were.
*/
export declare const KNOWLEDGE_MAX_PAGE_CHUNKS = 100;
/**
* The warning for content left out of the semantic index after every try failed, naming it (`page
* "docs:acme#guides"`, `note <id>`) so it can be rewritten.
* @internal
*/
export declare function knowledgeEmbedFailedWarning(subject: string): string;
/** A vector hit, before the caller checks the run can read it. @internal */
export type KnowledgeSemanticCandidate = {
kind: 'page' | 'note';
id: string;
};
/**
* Embeds ordinary pages (name, description, body) and notes into one vector index. A page too long
* to embed whole goes in as chunks, each led by the page's name and description; search counts a
* page once, at its best chunk. The index holds
* ids only: every hit is re-read through the store with the run's read scope before it counts, so a
* stale or foreign vector can never surface content, and access filtering happens before ranking.
* Writes index after the store commits; a failed embed only costs recall until the content next changes.
* @internal
*/
export declare class KnowledgeSemanticIndex {
#private;
private readonly vector;
private readonly embedder;
private readonly embedderOptions?;
/**
* Waits between tries of an embed or vector write that fails, about 10s in all: long enough for a
* scale-to-zero database (Neon, Lakebase) to wake, short enough not to hold a write up for long.
*/
static retryDelaysMs: readonly number[];
constructor(vector: MastraVector, embedder: MastraEmbeddingModel<string>, embedderOptions?: MastraEmbeddingOptions | undefined);
/**
* Returns how many chunks the body made before the {@link KNOWLEDGE_MAX_PAGE_CHUNKS} cap (0 when
* removed). `fromChunk` skips chunks an earlier call already stored. When an embed fails after
* retrying, the chunks before it are stored anyway and the error carries how many are in
* (`knowledgeStoredChunks`), so a caller resuming after a rate limit doesn't embed them again.
*/
indexPage(page: KnowledgePage, fromChunk?: number): Promise<number>;
/** Drops every chunk of a page from the index. */
removePage(pageId: string): Promise<void>;
indexNote(note: KnowledgeNote): Promise<void>;
remove(ids: string[]): Promise<void>;
/**
* The `limit` best candidates `accept` lets through, in vector order. Over-fetches and refills
* until enough are accepted or the index runs out, so hidden content neither takes result slots
* nor reorders what's left.
*/
search<T>(query: string, limit: number, accept: (candidate: KnowledgeSemanticCandidate) => Promise<T | null>): Promise<T[]>;
}
//# sourceMappingURL=semantic.d.ts.map