pulse-ai-utils
Version:
Utility functions and helpers for AI-powered applications
40 lines (39 loc) • 1.32 kB
TypeScript
/**
* Helper functions for working with pgvector data in Supabase
*/
/**
* Parse a pgvector string representation to a JavaScript array
* Handles the string format returned by Supabase: "[0.1,0.2,0.3,...]"
*/
export declare function parseVectorString(vectorString: string): number[];
/**
* Convert a JavaScript array to pgvector format for insertion
* This handles the proper formatting for Supabase/PostgreSQL
*/
export declare function formatVectorForInsert(vector: number[]): string;
/**
* Safely get embedding from Supabase response
* Handles both array and string formats
*/
export declare function getEmbeddingArray(data: any): number[] | null;
/**
* Calculate cosine similarity between two vectors
* Useful for client-side similarity calculations
*/
export declare function cosineSimilarity(vec1: number[], vec2: number[]): number;
/**
* Batch process content with embeddings
* Ensures proper formatting for bulk operations
*/
export declare function prepareContentForBulkInsert(documents: Array<{
id: string;
data: any;
embedding?: number[];
}>): Array<any>;
/**
* Transform Supabase response to ensure embeddings are arrays
* Use this after fetching data with embedding fields
*/
export declare function transformSupabaseResponse<T extends {
embedding?: any;
}>(data: T[]): T[];