import { Hooks } from './hooks.ts'; import { Metrics } from './metrics.ts'; import { NexusChat, type LoadOptions } from './chat.ts'; import { NexusEmbedder, type EmbedOptions } from './embed.ts'; import { MemoryIndex, type Chunk } from './rag.ts'; import { type ExportModelOptions } from './model.ts'; import type { ModelSource } from './source.ts'; import { type ArchiveSource, type ZipOptions } from './archive.ts'; export interface KnowledgeOptions { /** Where the chat model comes from — or an already-loaded NexusChat. */ chat: ModelSource | NexusChat; /** Where the embedding model comes from — or an already-loaded embedder. * Defaults to bge-small on the Hugging Face Hub; state it to use anything else. */ embedder?: ModelSource | NexusEmbedder; chatOptions?: LoadOptions; embedOptions?: EmbedOptions; /** Chunking: characters per chunk and overlap. */ chunkSize?: number; chunkOverlap?: number; /** How many chunks to retrieve per question. */ topK?: number; } export interface KnowledgeDoc { id: string; title?: string; text: string; meta?: Record; } export interface KnowledgeManifest { kind: 'knowledge'; version: 1; createdAt: string; models: { chat: string; embedder: string; }; docs: Array & { text?: string; }>; /** Which parts are actually inside this archive. */ contains: { rag: boolean; chatModel: boolean; embedModel: boolean; }; } export interface ExportKnowledgeOptions extends ZipOptions { /** Bundle the chat model weights (big — makes the archive self-contained). */ includeChatModel?: boolean; /** Bundle the embedding model weights. */ includeEmbedModel?: boolean; /** Shorthand for both of the above. */ includeModels?: boolean; /** Keep the original document text in the archive. Default true. */ includeText?: boolean; /** Passed through when packing models (dtype filter, modelsUrl, progress). */ modelOptions?: ExportModelOptions; onProgress?: (stage: string) => void; } type KnowledgeEvents = { indexing: [string, number]; indexed: [string, number]; retrieved: [Chunk[], string]; token: [string]; answer: [string]; }; /** * Offline knowledge system: documents in, grounded answers out — and the whole * thing packs into one zip. * * This is a *composition* of three independently portable artifacts: the chat * model, the embedding model, and the RAG store. Each of those has its own * export/import (`exportModel`/`importModel`, `exportIndex`/`importIndex`) if * you want to ship them separately; this class just zips all three together. * * const kb = await NexusKnowledge.create({ chat: 'Qwen/Qwen3-0.6B' }); * await kb.addDocument({ id: 'handbook', text: handbookText }); * const answer = await kb.ask('What is the refund policy?'); * * const zip = await kb.exportZip({ includeModels: true }); * const kb2 = await NexusKnowledge.importZip(zip); // works offline */ export declare class NexusKnowledge extends Hooks { readonly chat: NexusChat; readonly embedder: NexusEmbedder; readonly modelIds: { chat: string; embedder: string; }; readonly metrics: Metrics; index: MemoryIndex; readonly docs: Map; chunkSize: number; chunkOverlap: number; topK: number; private constructor(); static create(opts: KnowledgeOptions): Promise; /** Chunk, embed and index a document. */ addDocument(doc: KnowledgeDoc): Promise; addDocuments(docs: KnowledgeDoc[]): Promise; /** Retrieve the chunks most relevant to a question. */ retrieve(question: string, k?: number): Promise; /** * Retrieval-augmented answer. Context goes in the user turn — small models * attend to it far more reliably than to a system prompt. */ ask(question: string, opts?: { k?: number; maxNewTokens?: number; }): Promise; /** Serialize to a flat file map: manifest + rag/ + optionally the models. */ toFiles(opts?: ExportKnowledgeOptions): Promise>; /** Pack everything into one zip — the format to actually ship. */ exportZip(opts?: ExportKnowledgeOptions): Promise; /** * Restore from an archive: rehydrates the vector store (no re-embedding) and * any bundled model weights, then loads the models — from cache, so an * archive exported with `includeModels` needs no network at all. * Accepts a URL, a File from an , a Blob, or raw bytes. */ static importZip(source: ArchiveSource, opts?: Partial & ZipOptions): Promise; /** Peek at an archive's manifest without loading any models. */ static inspect(source: ArchiveSource, opts?: ZipOptions): Promise; dispose(): Promise; } export {};