sentence2simvecjs
Version:
Vector-based sentence similarity (0.0-1.0) + embedding export. JavaScript implementation inspired by PINTO0309/sentence2simvec
42 lines • 1.57 kB
TypeScript
export interface CorpusItem {
id: string;
text: string;
metadata?: any;
}
export interface CorpusSearchResult {
item: CorpusItem;
similarity: number;
method: 'dice' | 'embedding';
}
export interface CorpusOptions {
enableDiceCache?: boolean;
enableEmbeddingCache?: boolean;
cacheDir?: string;
persistCache?: boolean;
}
export declare class CorpusManager {
private corpus;
private embeddingCache;
private diceNGramCache;
private options;
constructor(options?: CorpusOptions);
addItem(text: string, id?: string, metadata?: any): Promise<CorpusItem>;
addItems(items: Array<{
text: string;
id?: string;
metadata?: any;
}>): Promise<CorpusItem[]>;
loadFromFile(filePath: string, format?: 'text' | 'json'): Promise<CorpusItem[]>;
searchByDice(query: string, topK?: number, threshold?: number, ngramSize?: number): Promise<CorpusSearchResult[]>;
searchByEmbedding(query: string, topK?: number, threshold?: number): Promise<CorpusSearchResult[]>;
search(query: string, method?: 'dice' | 'embedding' | 'both', topK?: number, threshold?: number): Promise<CorpusSearchResult[]>;
batchSimilarity(query: string, method?: 'dice' | 'embedding'): Promise<Map<string, number>>;
getItem(id: string): CorpusItem | undefined;
getAllItems(): CorpusItem[];
size(): number;
clear(): void;
exportCorpus(filePath: string): Promise<void>;
exportEmbeddings(filePath: string): Promise<void>;
private generateId;
}
//# sourceMappingURL=corpusManager.d.ts.map