verso-db 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +252 -0
- package/dist/BinaryHeap.d.ts +25 -0
- package/dist/BinaryHeap.d.ts.map +1 -0
- package/dist/Collection.d.ts +156 -0
- package/dist/Collection.d.ts.map +1 -0
- package/dist/HNSWIndex.d.ts +357 -0
- package/dist/HNSWIndex.d.ts.map +1 -0
- package/dist/MaxBinaryHeap.d.ts +63 -0
- package/dist/MaxBinaryHeap.d.ts.map +1 -0
- package/dist/Storage.d.ts +54 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/VectorDB.d.ts +44 -0
- package/dist/VectorDB.d.ts.map +1 -0
- package/dist/backends/DistanceBackend.d.ts +5 -0
- package/dist/backends/DistanceBackend.d.ts.map +1 -0
- package/dist/backends/JsDistanceBackend.d.ts +37 -0
- package/dist/backends/JsDistanceBackend.d.ts.map +1 -0
- package/dist/encoding/DeltaEncoder.d.ts +61 -0
- package/dist/encoding/DeltaEncoder.d.ts.map +1 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3732 -0
- package/dist/presets.d.ts +91 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/quantization/ScalarQuantizer.d.ts +114 -0
- package/dist/quantization/ScalarQuantizer.d.ts.map +1 -0
- package/dist/storage/BatchWriter.d.ts +104 -0
- package/dist/storage/BatchWriter.d.ts.map +1 -0
- package/dist/storage/BunStorageBackend.d.ts +58 -0
- package/dist/storage/BunStorageBackend.d.ts.map +1 -0
- package/dist/storage/MemoryBackend.d.ts +44 -0
- package/dist/storage/MemoryBackend.d.ts.map +1 -0
- package/dist/storage/OPFSBackend.d.ts +59 -0
- package/dist/storage/OPFSBackend.d.ts.map +1 -0
- package/dist/storage/StorageBackend.d.ts +66 -0
- package/dist/storage/StorageBackend.d.ts.map +1 -0
- package/dist/storage/WriteAheadLog.d.ts +111 -0
- package/dist/storage/WriteAheadLog.d.ts.map +1 -0
- package/dist/storage/createStorageBackend.d.ts +40 -0
- package/dist/storage/createStorageBackend.d.ts.map +1 -0
- package/dist/storage/index.d.ts +30 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +98 -0
- package/src/BinaryHeap.ts +131 -0
- package/src/Collection.ts +695 -0
- package/src/HNSWIndex.ts +1839 -0
- package/src/MaxBinaryHeap.ts +175 -0
- package/src/Storage.ts +435 -0
- package/src/VectorDB.ts +109 -0
- package/src/backends/DistanceBackend.ts +17 -0
- package/src/backends/JsDistanceBackend.ts +227 -0
- package/src/encoding/DeltaEncoder.ts +217 -0
- package/src/errors.ts +110 -0
- package/src/index.ts +138 -0
- package/src/presets.ts +229 -0
- package/src/quantization/ScalarQuantizer.ts +383 -0
- package/src/storage/BatchWriter.ts +336 -0
- package/src/storage/BunStorageBackend.ts +161 -0
- package/src/storage/MemoryBackend.ts +120 -0
- package/src/storage/OPFSBackend.ts +250 -0
- package/src/storage/StorageBackend.ts +74 -0
- package/src/storage/WriteAheadLog.ts +326 -0
- package/src/storage/createStorageBackend.ts +137 -0
- package/src/storage/index.ts +53 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all VectorDB errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class VectorDBError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(message: string, code: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when vector dimensions don't match expected dimensions
|
|
10
|
+
*/
|
|
11
|
+
export declare class DimensionMismatchError extends VectorDBError {
|
|
12
|
+
readonly expected: number;
|
|
13
|
+
readonly actual: number;
|
|
14
|
+
constructor(expected: number, actual: number, context?: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Thrown when attempting to add a vector with an ID that already exists
|
|
18
|
+
*/
|
|
19
|
+
export declare class DuplicateVectorError extends VectorDBError {
|
|
20
|
+
readonly ids: string[];
|
|
21
|
+
constructor(ids: string[]);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when a requested collection does not exist
|
|
25
|
+
*/
|
|
26
|
+
export declare class CollectionNotFoundError extends VectorDBError {
|
|
27
|
+
readonly collectionName: string;
|
|
28
|
+
constructor(collectionName: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Thrown when attempting to create a collection that already exists
|
|
32
|
+
*/
|
|
33
|
+
export declare class CollectionExistsError extends VectorDBError {
|
|
34
|
+
readonly collectionName: string;
|
|
35
|
+
constructor(collectionName: string);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when a storage operation fails
|
|
39
|
+
*/
|
|
40
|
+
export declare class StorageError extends VectorDBError {
|
|
41
|
+
readonly operation: string;
|
|
42
|
+
readonly path?: string;
|
|
43
|
+
constructor(operation: string, message: string, path?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Thrown when quantization operations fail
|
|
47
|
+
*/
|
|
48
|
+
export declare class QuantizationError extends VectorDBError {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when a vector is not found in the index
|
|
53
|
+
*/
|
|
54
|
+
export declare class VectorNotFoundError extends VectorDBError {
|
|
55
|
+
readonly vectorId: string | number;
|
|
56
|
+
constructor(vectorId: string | number);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM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+
* - HNSW algorithm for approximate nearest neighbor search
|
|
6
|
+
* - Multiple distance metrics: cosine, euclidean, dot product
|
|
7
|
+
* - Int8 scalar quantization for 4x memory reduction
|
|
8
|
+
* - Batch query support for improved throughput
|
|
9
|
+
* - Parameter presets for different use cases
|
|
10
|
+
* - Multi-platform: Bun (file system) and Browser (OPFS)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { VectorDB, getRecommendedPreset } from 'verso';
|
|
15
|
+
*
|
|
16
|
+
* const db = new VectorDB();
|
|
17
|
+
* const preset = getRecommendedPreset(768);
|
|
18
|
+
*
|
|
19
|
+
* const collection = await db.createCollection('my-vectors', {
|
|
20
|
+
* dimension: 768,
|
|
21
|
+
* metric: 'cosine',
|
|
22
|
+
* M: preset.M,
|
|
23
|
+
* efConstruction: preset.efConstruction
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* await collection.add({
|
|
27
|
+
* ids: ['doc1', 'doc2'],
|
|
28
|
+
* vectors: [new Float32Array(768), new Float32Array(768)]
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* const results = await collection.query({
|
|
32
|
+
* queryVector: new Float32Array(768),
|
|
33
|
+
* k: 10,
|
|
34
|
+
* efSearch: preset.efSearch
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @packageDocumentation
|
|
39
|
+
* @module verso
|
|
40
|
+
*/
|
|
41
|
+
export { VectorDB } from './VectorDB';
|
|
42
|
+
export type { VectorDBConfig } from './VectorDB';
|
|
43
|
+
export { Collection } from './Collection';
|
|
44
|
+
export type { AddConfig, QueryConfig, QueryResult } from './Collection';
|
|
45
|
+
export { HNSWIndex } from './HNSWIndex';
|
|
46
|
+
export type { DistanceMetric, Node } from './HNSWIndex';
|
|
47
|
+
export type { DistanceBackend } from './backends/DistanceBackend';
|
|
48
|
+
export { JsDistanceBackend, dotProductFast, l2SquaredFast, normalizeInPlace, cosineDistanceFast } from './backends/JsDistanceBackend';
|
|
49
|
+
export { BinaryHeap } from './BinaryHeap';
|
|
50
|
+
export { MaxBinaryHeap } from './MaxBinaryHeap';
|
|
51
|
+
export { ScalarQuantizer, QuantizedVectorStore, dotProductInt8, l2SquaredInt8, cosineDistanceInt8 } from './quantization/ScalarQuantizer';
|
|
52
|
+
export type { QuantizationParams } from './quantization/ScalarQuantizer';
|
|
53
|
+
export type { HNSWPreset } from './presets';
|
|
54
|
+
export { PRESET_LOW_DIM, PRESET_MEDIUM_DIM, PRESET_HIGH_DIM, PRESET_VERY_HIGH_DIM, PRESET_SMALL_DATASET, PRESET_LARGE_DATASET, PRESET_MAX_RECALL, PRESET_LOW_LATENCY, PRESETS, getRecommendedPreset, getPreset, getRAGPreset } from './presets';
|
|
55
|
+
export type { StorageBackend, StorageOptions } from './storage/StorageBackend';
|
|
56
|
+
export { BunStorageBackend } from './storage/BunStorageBackend';
|
|
57
|
+
export { MemoryBackend } from './storage/MemoryBackend';
|
|
58
|
+
export { OPFSBackend } from './storage/OPFSBackend';
|
|
59
|
+
export { createStorageBackend, getRecommendedStorageType, isStorageTypeAvailable, type StorageType, type CreateStorageOptions, } from './storage/createStorageBackend';
|
|
60
|
+
export { WriteAheadLog, WALOperationType, type WALEntry, } from './storage/WriteAheadLog';
|
|
61
|
+
export { BatchWriter, createBatchWriter, type BatchWriterOptions, } from './storage/BatchWriter';
|
|
62
|
+
export { deltaEncodeNeighbors, deltaDecodeNeighbors, deltaEncodedSize, encodeVarint, decodeVarint, } from './encoding/DeltaEncoder';
|
|
63
|
+
export { VectorDBError, DimensionMismatchError, DuplicateVectorError, CollectionNotFoundError, CollectionExistsError, StorageError, QuantizationError, VectorNotFoundError, } from './errors';
|
|
64
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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