File size: 3,694 Bytes
40d7073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
 * Vector entry representing a document with its embedding
 */
export interface VectorEntry {
    /** Unique identifier for the vector */
    id: string;
    /** Vector embedding (array of floats) */
    vector: number[];
    /** Optional metadata associated with the vector */
    metadata?: Record<string, any>;
}
/**
 * Search query parameters
 */
export interface SearchQuery {
    /** Query vector to search for */
    vector: number[];
    /** Number of results to return */
    k?: number;
    /** Optional metadata filters */
    filter?: Record<string, any>;
    /** Minimum similarity threshold (0-1) */
    threshold?: number;
}
/**
 * Search result containing matched vector and similarity score
 */
export interface SearchResult {
    /** ID of the matched vector */
    id: string;
    /** Similarity score (0-1, higher is better) */
    score: number;
    /** Vector data */
    vector: number[];
    /** Associated metadata */
    metadata?: Record<string, any>;
}
/**
 * Database configuration options
 */
export interface DbOptions {
    /** Vector dimension size */
    dimension: number;
    /** Distance metric to use */
    metric?: 'cosine' | 'euclidean' | 'dot';
    /** Path to persist database */
    path?: string;
    /** Enable auto-persistence */
    autoPersist?: boolean;
    /** HNSW index parameters */
    hnsw?: {
        /** Maximum number of connections per layer */
        m?: number;
        /** Size of the dynamic candidate list */
        efConstruction?: number;
        /** Size of the dynamic candidate list for search */
        efSearch?: number;
    };
}
/**
 * Database statistics
 */
export interface DbStats {
    /** Total number of vectors */
    count: number;
    /** Vector dimension */
    dimension: number;
    /** Distance metric */
    metric: string;
    /** Memory usage in bytes */
    memoryUsage?: number;
    /** Index type */
    indexType?: string;
}
/**
 * Main VectorDB class interface
 */
export interface VectorDB {
    /**
     * Create a new vector database
     * @param options Database configuration
     */
    new (options: DbOptions): VectorDB;
    /**
     * Insert a single vector
     * @param entry Vector entry to insert
     */
    insert(entry: VectorEntry): void;
    /**
     * Insert multiple vectors in batch
     * @param entries Array of vector entries
     */
    insertBatch(entries: VectorEntry[]): void;
    /**
     * Search for similar vectors
     * @param query Search query parameters
     * @returns Array of search results
     */
    search(query: SearchQuery): SearchResult[];
    /**
     * Get vector by ID
     * @param id Vector ID
     * @returns Vector entry or null
     */
    get(id: string): VectorEntry | null;
    /**
     * Delete vector by ID
     * @param id Vector ID
     * @returns true if deleted, false if not found
     */
    delete(id: string): boolean;
    /**
     * Update vector metadata
     * @param id Vector ID
     * @param metadata New metadata
     */
    updateMetadata(id: string, metadata: Record<string, any>): void;
    /**
     * Get database statistics
     */
    stats(): DbStats;
    /**
     * Save database to disk
     * @param path Optional path (uses configured path if not provided)
     */
    save(path?: string): void;
    /**
     * Load database from disk
     * @param path Path to database file
     */
    load(path: string): void;
    /**
     * Clear all vectors from database
     */
    clear(): void;
    /**
     * Build HNSW index for faster search
     */
    buildIndex(): void;
    /**
     * Optimize database (rebuild indices, compact storage)
     */
    optimize(): void;
}
//# sourceMappingURL=types.d.ts.map