@memberjunction/ai-vectordb 2.42.1 → 2.44.0
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/README.md +82 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ The MemberJunction AI Vector Database package provides a standardized interface
|
|
|
11
11
|
- **Type Definitions**: Comprehensive TypeScript type definitions
|
|
12
12
|
- **Provider Agnostic**: Works with any vector database that implements the interface
|
|
13
13
|
- **Standardized Response Format**: Consistent response format across providers
|
|
14
|
+
- **Secure API Key Management**: Protected API key handling with validation
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -26,6 +27,9 @@ The abstract base class that all vector database providers must implement:
|
|
|
26
27
|
|
|
27
28
|
```typescript
|
|
28
29
|
export abstract class VectorDBBase {
|
|
30
|
+
// Protected getter for API key access by subclasses
|
|
31
|
+
protected get apiKey(): string;
|
|
32
|
+
|
|
29
33
|
constructor(apiKey: string);
|
|
30
34
|
|
|
31
35
|
// Index operations
|
|
@@ -55,13 +59,20 @@ export abstract class VectorDBBase {
|
|
|
55
59
|
```typescript
|
|
56
60
|
export type VectorRecord<T extends RecordMetadata = RecordMetadata> = {
|
|
57
61
|
id: string; // Unique identifier for the record
|
|
58
|
-
values:
|
|
59
|
-
sparseValues?:
|
|
60
|
-
indices: number[];
|
|
61
|
-
values: number[];
|
|
62
|
-
};
|
|
62
|
+
values: RecordValues; // Vector embedding values (array of numbers)
|
|
63
|
+
sparseValues?: RecordSparseValues; // Optional sparse representation for hybrid search
|
|
63
64
|
metadata?: T; // Optional metadata for filtering and identification
|
|
64
65
|
};
|
|
66
|
+
|
|
67
|
+
export type RecordValues = Array<number>;
|
|
68
|
+
|
|
69
|
+
export type RecordSparseValues = {
|
|
70
|
+
indices: Array<number>; // List of indices where non-zero values are present
|
|
71
|
+
values: Array<number>; // The values that correspond to the positions in indices
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type RecordMetadataValue = string | boolean | number | Array<string>;
|
|
75
|
+
export type RecordMetadata = Record<string, RecordMetadataValue>;
|
|
65
76
|
```
|
|
66
77
|
|
|
67
78
|
#### Index Description
|
|
@@ -90,7 +101,7 @@ export type QueryParamsBase = {
|
|
|
90
101
|
|
|
91
102
|
// Query by vector values
|
|
92
103
|
export type QueryByVectorValues = QueryParamsBase & {
|
|
93
|
-
vector:
|
|
104
|
+
vector: RecordValues; // The query vector to find similar vectors for
|
|
94
105
|
};
|
|
95
106
|
|
|
96
107
|
// Query by record ID
|
|
@@ -112,8 +123,12 @@ export type QueryResponse<T extends RecordMetadata = RecordMetadata> = {
|
|
|
112
123
|
};
|
|
113
124
|
|
|
114
125
|
export interface ScoredRecord<T extends RecordMetadata = RecordMetadata> extends VectorRecord<T> {
|
|
115
|
-
score?: number; // Similarity score
|
|
126
|
+
score?: number; // Similarity score (interpretation depends on metric)
|
|
116
127
|
}
|
|
128
|
+
|
|
129
|
+
export type OperationUsage = {
|
|
130
|
+
readUnits?: number; // Number of read units consumed by operation
|
|
131
|
+
};
|
|
117
132
|
```
|
|
118
133
|
|
|
119
134
|
## Usage Examples
|
|
@@ -141,7 +156,7 @@ class MyVectorDBProvider extends VectorDBBase {
|
|
|
141
156
|
};
|
|
142
157
|
}
|
|
143
158
|
|
|
144
|
-
async createIndex(params: CreateIndexParams) {
|
|
159
|
+
async createIndex(params: CreateIndexParams): Promise<BaseResponse> {
|
|
145
160
|
// Implementation for creating an index
|
|
146
161
|
try {
|
|
147
162
|
// Provider-specific code
|
|
@@ -179,7 +194,7 @@ async function workWithVectors() {
|
|
|
179
194
|
const createResult = await vectorDB.createIndex({
|
|
180
195
|
id: 'my-index',
|
|
181
196
|
dimension: 1536,
|
|
182
|
-
metric: 'cosine'
|
|
197
|
+
metric: 'cosine' as IndexModelMetricEnum
|
|
183
198
|
});
|
|
184
199
|
|
|
185
200
|
if (createResult.success) {
|
|
@@ -228,10 +243,66 @@ This package integrates with the broader MemberJunction AI vector ecosystem:
|
|
|
228
243
|
- `@memberjunction/ai-vectors-sync` - Synchronize entity data to vector databases
|
|
229
244
|
- `@memberjunction/ai-vectors-dupe` - Duplicate detection using vector similarity
|
|
230
245
|
|
|
246
|
+
## Error Handling
|
|
247
|
+
|
|
248
|
+
The VectorDBBase constructor validates the API key and throws an error if it's empty or invalid:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
try {
|
|
252
|
+
const vectorDB = new MyVectorDBProvider('');
|
|
253
|
+
} catch (error) {
|
|
254
|
+
// Error: API key cannot be empty
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
All methods return a standardized `BaseResponse` format:
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
export type BaseResponse = {
|
|
262
|
+
success: boolean; // Whether the operation succeeded
|
|
263
|
+
message: string; // Human-readable message about the operation
|
|
264
|
+
data: any; // Operation-specific response data
|
|
265
|
+
};
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Additional Types
|
|
269
|
+
|
|
270
|
+
### Request Parameters
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
export type BaseRequestParams = {
|
|
274
|
+
id: string;
|
|
275
|
+
data?: any;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export type CreateIndexParams = BaseRequestParams & {
|
|
279
|
+
dimension: number;
|
|
280
|
+
metric: IndexModelMetricEnum;
|
|
281
|
+
additionalParams?: any;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export type EditIndexParams = BaseRequestParams & {
|
|
285
|
+
// Additional fields specific to the provider
|
|
286
|
+
};
|
|
287
|
+
```
|
|
288
|
+
|
|
231
289
|
## Dependencies
|
|
232
290
|
|
|
233
|
-
- `@memberjunction/core`: MemberJunction core library
|
|
234
|
-
- `@memberjunction/global`: MemberJunction global utilities
|
|
291
|
+
- `@memberjunction/core`: ^2.43.0 - MemberJunction core library
|
|
292
|
+
- `@memberjunction/global`: ^2.43.0 - MemberJunction global utilities
|
|
293
|
+
- `dotenv`: ^16.4.1 - Environment variable management
|
|
294
|
+
|
|
295
|
+
## Development Dependencies
|
|
296
|
+
|
|
297
|
+
- `@types/node`: 20.14.2
|
|
298
|
+
- `ts-node-dev`: ^2.0.0
|
|
299
|
+
- `typescript`: ^5.4.5
|
|
300
|
+
|
|
301
|
+
## Scripts
|
|
302
|
+
|
|
303
|
+
- `npm run build` - Compile TypeScript to JavaScript
|
|
304
|
+
- `npm run start` - Run the development server with ts-node-dev
|
|
305
|
+
- `npm test` - Run tests (currently not implemented)
|
|
235
306
|
|
|
236
307
|
## License
|
|
237
308
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-vectordb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "MemberJunction: AI Vector Database Module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"author": "MemberJunction.com",
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@memberjunction/core": "2.
|
|
19
|
-
"@memberjunction/global": "2.
|
|
18
|
+
"@memberjunction/core": "2.44.0",
|
|
19
|
+
"@memberjunction/global": "2.44.0",
|
|
20
20
|
"dotenv": "^16.4.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|