ai-embed-search
Version:
Smart. Simple. Local. AI-powered semantic search in TypeScript using transformer embeddings. No cloud, no API keys — 100% offline.
52 lines (47 loc) • 1.53 kB
TypeScript
type SearchItem = {
id: string;
text: string;
meta?: Record<string, any>;
};
type SearchResult = {
id: string;
text: string;
score: number;
meta?: Record<string, any>;
};
type EmbedFn = ((text: string) => Promise<number[]>) | ((texts: string[]) => Promise<number[][]>);
type VectorEntry = {
id: string;
text: string;
vector: number[];
meta?: Record<string, any>;
};
declare function initEmbedder(options: {
embedder: EmbedFn;
}): void;
declare function embed(items: SearchItem[]): Promise<void>;
declare function search(query: string, maxItems?: number): {
filter(fn: (result: SearchResult) => boolean): /*elided*/ any;
exec: () => Promise<SearchResult[]>;
cacheFor: (seconds: number) => Promise<SearchResult[]>;
};
declare function getSimilarItems(id: string, maxItems?: number): Promise<SearchResult[]>;
declare let vectorStore: VectorEntry[];
/**
* Save current vector store to a file.
*/
declare function saveVectors(filePath: string): Promise<void>;
/**
* Load vector store from a JSON file.
*/
declare function loadVectors(filePath: string): Promise<void>;
/**
* Remove a vector entry by ID.
*/
declare function removeVector(id: string): void;
/**
* Clear all vector entries.
*/
declare function clearVectors(): void;
declare function createEmbedder(): Promise<(text: string) => Promise<number[]>>;
export { vectorStore as _vectorStore, clearVectors, createEmbedder, embed, getSimilarItems, initEmbedder, loadVectors, removeVector, saveVectors, search };