edgevector
Version:
Official TypeScript/JavaScript SDK for EdgeVector - Edge-native multi-paradigm database with AI-first features
218 lines (216 loc) • 6.45 kB
TypeScript
/**
* EdgeVector SDK
* Official TypeScript/JavaScript client for EdgeVector
*
* @version 1.0.0
* @author EdgeVector Team
*/
interface EdgeVectorConfig {
/** API endpoint URL */
endpoint?: string;
/** API key for authentication */
apiKey?: string;
/** Request timeout in milliseconds */
timeout?: number;
/** Number of retry attempts */
retries?: number;
/** Enable request/response caching */
cache?: boolean;
/** Enable gzip compression */
compression?: boolean;
/** Custom headers to include with requests */
headers?: Record<string, string>;
/** Regional endpoint preference */
region?: 'us-east' | 'us-west' | 'eu-west' | 'ap-southeast';
}
interface Document {
_id?: string;
[key: string]: any;
}
interface Vector {
id: string;
vector: number[];
metadata?: Record<string, any>;
score?: number;
}
interface VectorSearchOptions {
/** Search vector or text query */
vector?: number[];
text?: string;
/** Number of results to return */
limit?: number;
/** Minimum similarity threshold */
threshold?: number;
/** Metadata filters */
filter?: Record<string, any>;
/** Include metadata in results */
includeMetadata?: boolean;
/** Include vectors in results */
includeVectors?: boolean;
}
interface TimeSeriesPoint {
metric: string;
value: number;
timestamp?: number;
tags?: Record<string, string>;
}
interface TimeSeriesQuery {
metric: string;
start?: string | number;
end?: string | number;
aggregation?: 'avg' | 'sum' | 'min' | 'max' | 'count';
groupBy?: string[];
filters?: Record<string, any>;
}
interface HybridSearchOptions extends VectorSearchOptions {
/** Combine vector similarity with text search */
textQuery?: string;
/** Weight for vector similarity (0-1) */
vectorWeight?: number;
/** Weight for text relevance (0-1) */
textWeight?: number;
}
interface StreamOptions {
/** Collections to watch */
collections?: string[];
/** Operations to monitor */
operations?: ('insert' | 'update' | 'delete')[];
/** Initial filters */
filter?: Record<string, any>;
}
/**
* Main EdgeVector client class
*/
declare class EdgeVector {
private config;
private cache;
constructor(config?: EdgeVectorConfig);
/**
* Make HTTP request with retry logic
*/
private request;
/**
* Get database health status
*/
health(): Promise<{
status: string;
services: Record<string, string>;
}>;
/**
* Get a collection reference
*/
collection(name: string): Collection;
/**
* Create a database reference
*/
db(name?: string): Database;
/**
* AI operations
*/
get ai(): AIOperations;
/**
* Time series operations
*/
timeseries(collection: string): TimeSeriesOperations;
/**
* Create real-time stream
*/
stream(options?: StreamOptions): Promise<EventSource>;
/**
* Quick start helper for common use cases
*/
static quickStart(apiKey?: string, appName?: string): EdgeVector;
}
/**
* Database operations
*/
declare class Database {
private client;
private name;
constructor(client: EdgeVector, name: string);
collection(name: string): Collection;
createCollection(name: string, options?: any): Promise<void>;
dropCollection(name: string): Promise<void>;
listCollections(): Promise<string[]>;
}
/**
* Collection operations
*/
declare class Collection {
private client;
private name;
constructor(client: EdgeVector, name: string);
insertOne(document: Document): Promise<{
insertedId: string;
}>;
insertMany(documents: Document[]): Promise<{
insertedIds: string[];
}>;
findOne(filter?: Record<string, any>): Promise<Document | null>;
find(filter?: Record<string, any>, options?: any): Promise<Document[]>;
updateOne(filter: Record<string, any>, update: Record<string, any>): Promise<{
modifiedCount: number;
}>;
updateMany(filter: Record<string, any>, update: Record<string, any>): Promise<{
modifiedCount: number;
}>;
deleteOne(filter: Record<string, any>): Promise<{
deletedCount: number;
}>;
deleteMany(filter: Record<string, any>): Promise<{
deletedCount: number;
}>;
aggregate(pipeline: any[]): Promise<any[]>;
vectorSearch(options: VectorSearchOptions): Promise<Vector[]>;
hybridSearch(options: HybridSearchOptions): Promise<Vector[]>;
vectors(): VectorOperations;
timeseries(): TimeSeriesOperations;
watch(filter: Record<string, any> | undefined, callback: (event: any) => void): Promise<() => void>;
}
/**
* Vector-specific operations
*/
declare class VectorOperations {
private client;
private collection;
constructor(client: EdgeVector, collection: string);
insert(vector: number[], metadata?: Record<string, any>): Promise<{
id: string;
}>;
search(vector: number[], options?: Omit<VectorSearchOptions, 'vector'>): Promise<Vector[]>;
generateEmbedding(text: string): Promise<{
vector: number[];
model: string;
}>;
similaritySearch(text: string, options?: Omit<VectorSearchOptions, 'text'>): Promise<Vector[]>;
}
/**
* Time series operations
*/
declare class TimeSeriesOperations {
private client;
private collection;
constructor(client: EdgeVector, collection: string);
write(points: TimeSeriesPoint | TimeSeriesPoint[]): Promise<void>;
query(options: TimeSeriesQuery): Promise<any[]>;
detectAnomalies(metric: string, options?: any): Promise<any[]>;
}
/**
* AI operations
*/
declare class AIOperations {
private client;
constructor(client: EdgeVector);
embed(text: string, model?: string): Promise<{
vector: number[];
model: string;
}>;
embedBatch(texts: string[], model?: string): Promise<{
vectors: number[][];
model: string;
}>;
chat(messages: any[], options?: any): Promise<any>;
}
declare function quickStart(apiKey?: string, appName?: string): EdgeVector;
export { AIOperations, Collection, Database, EdgeVector, TimeSeriesOperations, VectorOperations, EdgeVector as default, quickStart };
export type { Document, EdgeVectorConfig, HybridSearchOptions, StreamOptions, TimeSeriesPoint, TimeSeriesQuery, Vector, VectorSearchOptions };