UNPKG

@craftapit/tester

Version:

A focused, LLM-powered testing framework for natural language test scenarios

70 lines (69 loc) 2.13 kB
/** * A simple vector store implementation for context action caching * This provides a lightweight alternative to full vector database implementations * when you need to store and query embeddings */ export declare class VectorStore { private vectors; private dimension; constructor(dimension?: number); /** * Add a vector to the store * @param id Unique identifier for the vector * @param vector The embedding vector * @param metadata Additional metadata to store with the vector */ addVector(id: string, vector: number[], metadata?: Record<string, any>): void; /** * Remove a vector from the store * @param id The ID of the vector to remove * @returns true if the vector was removed, false if it wasn't found */ removeVector(id: string): boolean; /** * Find the nearest neighbors to a query vector * @param queryVector The query vector * @param k The number of neighbors to return * @returns The k nearest neighbors */ findNearest(queryVector: number[], k?: number): Array<{ id: string; similarity: number; metadata: Record<string, any>; }>; /** * Calculate the cosine similarity between two vectors * @param a First vector * @param b Second vector * @returns Cosine similarity (-1 to 1, where 1 is identical) */ private cosineSimilarity; /** * Get all vectors in the store * @returns All vectors */ getAllVectors(): Array<{ id: string; vector: number[]; metadata: Record<string, any>; }>; /** * Get the number of vectors in the store * @returns The number of vectors */ size(): number; /** * Clear all vectors from the store */ clear(): void; /** * Save the vector store to a JSON string * @returns JSON string representation of the vector store */ saveToJson(): string; /** * Load the vector store from a JSON string * @param json JSON string representation of the vector store */ loadFromJson(json: string): void; }