voctar 0.1.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/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/src/chunking/index.d.ts +48 -0
- package/dist/src/chunking/index.d.ts.map +1 -0
- package/dist/src/chunking/index.js +123 -0
- package/dist/src/chunking/index.js.map +1 -0
- package/dist/src/chunking/strategies/fixed.d.ts +14 -0
- package/dist/src/chunking/strategies/fixed.d.ts.map +1 -0
- package/dist/src/chunking/strategies/fixed.js +111 -0
- package/dist/src/chunking/strategies/fixed.js.map +1 -0
- package/dist/src/chunking/strategies/paragraph.d.ts +6 -0
- package/dist/src/chunking/strategies/paragraph.d.ts.map +1 -0
- package/dist/src/chunking/strategies/paragraph.js +84 -0
- package/dist/src/chunking/strategies/paragraph.js.map +1 -0
- package/dist/src/chunking/strategies/recursive.d.ts +17 -0
- package/dist/src/chunking/strategies/recursive.d.ts.map +1 -0
- package/dist/src/chunking/strategies/recursive.js +192 -0
- package/dist/src/chunking/strategies/recursive.js.map +1 -0
- package/dist/src/chunking/strategies/semantic.d.ts +96 -0
- package/dist/src/chunking/strategies/semantic.d.ts.map +1 -0
- package/dist/src/chunking/strategies/semantic.js +587 -0
- package/dist/src/chunking/strategies/semantic.js.map +1 -0
- package/dist/src/chunking/strategies/sentence.d.ts +7 -0
- package/dist/src/chunking/strategies/sentence.d.ts.map +1 -0
- package/dist/src/chunking/strategies/sentence.js +116 -0
- package/dist/src/chunking/strategies/sentence.js.map +1 -0
- package/dist/src/chunking/types.d.ts +45 -0
- package/dist/src/chunking/types.d.ts.map +1 -0
- package/dist/src/chunking/types.js +4 -0
- package/dist/src/chunking/types.js.map +1 -0
- package/dist/src/chunking/utils/tokenizer.d.ts +10 -0
- package/dist/src/chunking/utils/tokenizer.d.ts.map +1 -0
- package/dist/src/chunking/utils/tokenizer.js +50 -0
- package/dist/src/chunking/utils/tokenizer.js.map +1 -0
- package/dist/src/providers/embeddings/index.d.ts +3 -0
- package/dist/src/providers/embeddings/index.d.ts.map +1 -0
- package/dist/src/providers/embeddings/index.js +7 -0
- package/dist/src/providers/embeddings/index.js.map +1 -0
- package/dist/src/providers/embeddings/openai.d.ts +21 -0
- package/dist/src/providers/embeddings/openai.d.ts.map +1 -0
- package/dist/src/providers/embeddings/openai.js +86 -0
- package/dist/src/providers/embeddings/openai.js.map +1 -0
- package/dist/src/providers/index.d.ts +3 -0
- package/dist/src/providers/index.d.ts.map +1 -0
- package/dist/src/providers/index.js +20 -0
- package/dist/src/providers/index.js.map +1 -0
- package/dist/src/providers/stores/index.d.ts +6 -0
- package/dist/src/providers/stores/index.d.ts.map +1 -0
- package/dist/src/providers/stores/index.js +11 -0
- package/dist/src/providers/stores/index.js.map +1 -0
- package/dist/src/providers/stores/memory.d.ts +18 -0
- package/dist/src/providers/stores/memory.d.ts.map +1 -0
- package/dist/src/providers/stores/memory.js +169 -0
- package/dist/src/providers/stores/memory.js.map +1 -0
- package/dist/src/providers/stores/qdrant.d.ts +28 -0
- package/dist/src/providers/stores/qdrant.d.ts.map +1 -0
- package/dist/src/providers/stores/qdrant.js +223 -0
- package/dist/src/providers/stores/qdrant.js.map +1 -0
- package/dist/src/providers/stores/sqlite.d.ts +38 -0
- package/dist/src/providers/stores/sqlite.d.ts.map +1 -0
- package/dist/src/providers/stores/sqlite.js +306 -0
- package/dist/src/providers/stores/sqlite.js.map +1 -0
- package/dist/src/types.d.ts +111 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +32 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/vector.d.ts +74 -0
- package/dist/src/vector.d.ts.map +1 -0
- package/dist/src/vector.js +505 -0
- package/dist/src/vector.js.map +1 -0
- package/docs/API.md +361 -0
- package/docs/CHUNKING.md +280 -0
- package/docs/CUSTOM_PROVIDERS.md +101 -0
- package/docs/README.md +11 -0
- package/docs/STORAGE_BACKENDS.md +189 -0
- package/docs/assets/vectar.png +0 -0
- package/package.json +46 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Vector = void 0;
|
|
37
|
+
// Vector embedding service - simple interface with automatic chunking
|
|
38
|
+
const uuid_1 = require("uuid");
|
|
39
|
+
const types_1 = require("./types");
|
|
40
|
+
const openai_1 = require("./providers/embeddings/openai");
|
|
41
|
+
const qdrant_1 = require("./providers/stores/qdrant");
|
|
42
|
+
const memory_1 = require("./providers/stores/memory");
|
|
43
|
+
const sqlite_1 = require("./providers/stores/sqlite");
|
|
44
|
+
const chunking_1 = require("./chunking");
|
|
45
|
+
class Vector {
|
|
46
|
+
constructor(config) {
|
|
47
|
+
// Initialize providers
|
|
48
|
+
this.embeddingProvider = this.resolveEmbeddingProvider(config);
|
|
49
|
+
this.vectorStoreProvider = this.resolveVectorStoreProvider(config);
|
|
50
|
+
// Initialize chunking defaults
|
|
51
|
+
this.defaultChunkSize = config?.defaultChunkSize ?? 1000;
|
|
52
|
+
this.defaultChunkStrategy = config?.defaultChunkStrategy ?? 'recursive';
|
|
53
|
+
this.defaultChunkOverlap = config?.defaultChunkOverlap ?? 200;
|
|
54
|
+
this.autoChunk = config?.autoChunk ?? true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Embed text into a collection - automatically chunks if needed
|
|
58
|
+
* If documentId already exists, it will be overwritten (all old chunks deleted first)
|
|
59
|
+
* @returns Document ID and chunk IDs
|
|
60
|
+
*/
|
|
61
|
+
async embed(collection, text, options) {
|
|
62
|
+
this.validateCollectionName(collection);
|
|
63
|
+
this.validateText(text);
|
|
64
|
+
const documentId = options?.documentId || (0, uuid_1.v4)();
|
|
65
|
+
const shouldChunk = options?.autoChunk ?? this.autoChunk;
|
|
66
|
+
const chunkSize = options?.chunkSize ?? this.defaultChunkSize;
|
|
67
|
+
// Ensure collection exists
|
|
68
|
+
const dimension = this.embeddingProvider.getDimension();
|
|
69
|
+
await this.vectorStoreProvider.ensureCollection(collection, dimension);
|
|
70
|
+
try {
|
|
71
|
+
// If documentId was provided, delete any existing chunks first
|
|
72
|
+
// This prevents orphaned chunks when re-embedding with different chunk counts
|
|
73
|
+
if (options?.documentId) {
|
|
74
|
+
try {
|
|
75
|
+
await this.delete(collection, documentId);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Ignore errors if document doesn't exist
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Determine if chunking is needed based on token count
|
|
82
|
+
// Get token limit from embedding provider to ensure we don't exceed it
|
|
83
|
+
const tokenLimit = this.embeddingProvider.getTokenLimit();
|
|
84
|
+
const actualChunkSize = Math.min(chunkSize, tokenLimit); // Ensure chunk size doesn't exceed model limit
|
|
85
|
+
// Import token counter
|
|
86
|
+
const { countTokens } = await Promise.resolve().then(() => __importStar(require('./chunking/utils/tokenizer')));
|
|
87
|
+
const textTokens = countTokens(text);
|
|
88
|
+
const needsChunking = shouldChunk && textTokens > actualChunkSize;
|
|
89
|
+
if (needsChunking) {
|
|
90
|
+
// Chunk the document using token-based limits
|
|
91
|
+
const chunkOptions = {
|
|
92
|
+
strategy: options?.chunkStrategy ?? this.defaultChunkStrategy,
|
|
93
|
+
maxChunkSize: actualChunkSize, // Token limit, not character limit
|
|
94
|
+
overlap: options?.chunkOverlap ?? this.defaultChunkOverlap,
|
|
95
|
+
metadata: options?.metadata,
|
|
96
|
+
tokenLimit, // Pass token limit to strategies
|
|
97
|
+
};
|
|
98
|
+
// For semantic chunking, pass the embedding provider
|
|
99
|
+
if (chunkOptions.strategy === 'semantic') {
|
|
100
|
+
chunkOptions.embeddingProvider = this.embeddingProvider;
|
|
101
|
+
}
|
|
102
|
+
const chunkResult = chunking_1.chunking.chunkDocument(text, chunkOptions, documentId);
|
|
103
|
+
// Prepare documents for batch embedding with chunk IDs in format: documentId#chunkIndex
|
|
104
|
+
const createdAt = Date.now();
|
|
105
|
+
const documents = chunkResult.chunks.map(chunk => {
|
|
106
|
+
const chunkId = `${documentId}#${chunk.metadata.chunkIndex}`;
|
|
107
|
+
// Separate system metadata from user metadata
|
|
108
|
+
const systemMetadata = {
|
|
109
|
+
documentId: chunk.metadata.documentId,
|
|
110
|
+
chunkIndex: chunk.metadata.chunkIndex,
|
|
111
|
+
totalChunks: chunk.metadata.totalChunks,
|
|
112
|
+
startChar: chunk.metadata.startChar,
|
|
113
|
+
endChar: chunk.metadata.endChar,
|
|
114
|
+
createdAt,
|
|
115
|
+
_isChunk: true,
|
|
116
|
+
_documentId: documentId,
|
|
117
|
+
_chunkId: chunkId,
|
|
118
|
+
// Include semantic chunking system metadata if present
|
|
119
|
+
...(chunk.metadata.header && { header: chunk.metadata.header }),
|
|
120
|
+
...(chunk.metadata.dependsOn && { dependsOn: chunk.metadata.dependsOn }),
|
|
121
|
+
...(chunk.metadata.topicVolatility && { topicVolatility: chunk.metadata.topicVolatility }),
|
|
122
|
+
...(chunk.metadata.roles && { roles: chunk.metadata.roles }),
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
id: chunkId,
|
|
126
|
+
text: chunk.text,
|
|
127
|
+
metadata: {
|
|
128
|
+
system: systemMetadata,
|
|
129
|
+
metadata: options?.metadata || {},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
// Embed all chunks
|
|
134
|
+
const chunkIds = await this.embedBatch(collection, documents, options?.user_id);
|
|
135
|
+
return { documentId, chunkIds };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// Single document, no chunking needed
|
|
139
|
+
// Verify it doesn't exceed token limit
|
|
140
|
+
const textTokens = countTokens(text);
|
|
141
|
+
const tokenLimit = this.embeddingProvider.getTokenLimit();
|
|
142
|
+
if (textTokens > tokenLimit) {
|
|
143
|
+
// Force chunking even if autoChunk is false when document exceeds limit
|
|
144
|
+
throw new types_1.VectorEmbeddingError(`Document exceeds token limit (${textTokens} > ${tokenLimit}). ` +
|
|
145
|
+
`Enable chunking or reduce document size.`);
|
|
146
|
+
}
|
|
147
|
+
const vector = await this.embeddingProvider.embed(text);
|
|
148
|
+
const createdAt = Date.now();
|
|
149
|
+
await this.vectorStoreProvider.upsert(collection, [
|
|
150
|
+
{
|
|
151
|
+
id: documentId,
|
|
152
|
+
vector,
|
|
153
|
+
payload: {
|
|
154
|
+
text,
|
|
155
|
+
system: {
|
|
156
|
+
_documentId: documentId,
|
|
157
|
+
_isChunk: false,
|
|
158
|
+
createdAt,
|
|
159
|
+
},
|
|
160
|
+
metadata: options?.metadata || {},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
return { documentId, chunkIds: [documentId] };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
throw new types_1.VectorEmbeddingError(`Failed to embed document: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Embed multiple documents in batch
|
|
173
|
+
*/
|
|
174
|
+
async embedBatch(collection, documents, user_id) {
|
|
175
|
+
this.validateCollectionName(collection);
|
|
176
|
+
if (documents.length === 0) {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
// Ensure collection exists
|
|
181
|
+
const dimension = this.embeddingProvider.getDimension();
|
|
182
|
+
await this.vectorStoreProvider.ensureCollection(collection, dimension);
|
|
183
|
+
// Validate and re-chunk documents that exceed token limit
|
|
184
|
+
const tokenLimit = this.embeddingProvider.getTokenLimit();
|
|
185
|
+
const { countTokens } = await Promise.resolve().then(() => __importStar(require('./chunking/utils/tokenizer')));
|
|
186
|
+
const { chunking } = await Promise.resolve().then(() => __importStar(require('./chunking')));
|
|
187
|
+
const validDocuments = [];
|
|
188
|
+
const texts = [];
|
|
189
|
+
for (const doc of documents) {
|
|
190
|
+
this.validateText(doc.text);
|
|
191
|
+
const tokenCount = countTokens(doc.text);
|
|
192
|
+
if (tokenCount > tokenLimit) {
|
|
193
|
+
// Re-chunk this document using recursive strategy
|
|
194
|
+
console.warn(`Document ${doc.id} exceeds token limit (${tokenCount} > ${tokenLimit}). ` +
|
|
195
|
+
`Automatically re-chunking to preserve data.`);
|
|
196
|
+
// Extract parent document ID and chunk index from the chunk ID
|
|
197
|
+
// Format: documentId#chunkIndex
|
|
198
|
+
const parentDocId = doc.id.split('#')[0];
|
|
199
|
+
const parentChunkIndex = doc.id.includes('#') ? parseInt(doc.id.split('#')[1]) : undefined;
|
|
200
|
+
// Re-chunk with a smaller size (use 80% of token limit for safety)
|
|
201
|
+
const safeChunkSize = Math.floor(tokenLimit * 0.8);
|
|
202
|
+
const chunkOptions = {
|
|
203
|
+
strategy: 'recursive',
|
|
204
|
+
maxChunkSize: safeChunkSize,
|
|
205
|
+
overlap: Math.floor(safeChunkSize * 0.1), // 10% overlap
|
|
206
|
+
tokenLimit,
|
|
207
|
+
};
|
|
208
|
+
const chunkResult = chunking.chunkDocument(doc.text, chunkOptions, parentDocId);
|
|
209
|
+
// Create sub-chunks with proper IDs
|
|
210
|
+
for (let i = 0; i < chunkResult.chunks.length; i++) {
|
|
211
|
+
const subChunk = chunkResult.chunks[i];
|
|
212
|
+
// Create sub-chunk ID: parentChunkId#subIndex
|
|
213
|
+
const subChunkId = parentChunkIndex !== undefined
|
|
214
|
+
? `${parentDocId}#${parentChunkIndex}.${i}`
|
|
215
|
+
: `${doc.id}.${i}`;
|
|
216
|
+
validDocuments.push({
|
|
217
|
+
id: subChunkId,
|
|
218
|
+
text: subChunk.text,
|
|
219
|
+
metadata: {
|
|
220
|
+
...doc.metadata,
|
|
221
|
+
system: {
|
|
222
|
+
...(doc.metadata?.system || {}),
|
|
223
|
+
_isSubChunk: true,
|
|
224
|
+
_parentChunkId: doc.id,
|
|
225
|
+
_subChunkIndex: i,
|
|
226
|
+
_totalSubChunks: chunkResult.chunks.length,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
texts.push(subChunk.text);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
validDocuments.push(doc);
|
|
235
|
+
texts.push(doc.text);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (texts.length === 0) {
|
|
239
|
+
throw new types_1.VectorEmbeddingError('All documents exceeded token limit and could not be re-chunked');
|
|
240
|
+
}
|
|
241
|
+
// Generate embeddings in batch
|
|
242
|
+
const vectors = await this.embeddingProvider.embedBatch(texts);
|
|
243
|
+
// Prepare points for upsert.
|
|
244
|
+
// Keep one payload schema across embed() and embedBatch():
|
|
245
|
+
// - system fields in payload.system
|
|
246
|
+
// - caller metadata in payload.metadata
|
|
247
|
+
const points = validDocuments.map((doc, index) => {
|
|
248
|
+
const rawMetadata = doc.metadata || {};
|
|
249
|
+
const rawSystem = rawMetadata.system && typeof rawMetadata.system === 'object'
|
|
250
|
+
? rawMetadata.system
|
|
251
|
+
: undefined;
|
|
252
|
+
const nestedMetadata = rawMetadata.metadata && typeof rawMetadata.metadata === 'object'
|
|
253
|
+
? rawMetadata.metadata
|
|
254
|
+
: undefined;
|
|
255
|
+
const extraMetadata = Object.fromEntries(Object.entries(rawMetadata).filter(([key]) => key !== 'system' && key !== 'metadata'));
|
|
256
|
+
return {
|
|
257
|
+
id: doc.id || (0, uuid_1.v4)(),
|
|
258
|
+
vector: vectors[index],
|
|
259
|
+
payload: {
|
|
260
|
+
text: doc.text,
|
|
261
|
+
...(rawSystem ? { system: rawSystem } : {}),
|
|
262
|
+
metadata: {
|
|
263
|
+
...(nestedMetadata || {}),
|
|
264
|
+
...extraMetadata,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
// Store in vector database
|
|
270
|
+
await this.vectorStoreProvider.upsert(collection, points);
|
|
271
|
+
// Usage tracking can be handled by host applications.
|
|
272
|
+
void user_id;
|
|
273
|
+
return points.map(p => p.id);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new types_1.VectorEmbeddingError(`Failed to embed batch: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Search for similar documents
|
|
281
|
+
*/
|
|
282
|
+
async search(collection, query, options) {
|
|
283
|
+
this.validateCollectionName(collection);
|
|
284
|
+
this.validateText(query);
|
|
285
|
+
try {
|
|
286
|
+
// Generate query embedding
|
|
287
|
+
const vector = await this.embeddingProvider.embed(query);
|
|
288
|
+
// Search in vector database
|
|
289
|
+
await this.ensureCollection(collection);
|
|
290
|
+
const rawResults = await this.vectorStoreProvider.search(collection, vector, options ?? {});
|
|
291
|
+
// Separate system metadata from user metadata and extract createdAt
|
|
292
|
+
const includeSystem = options?.includeSystem ?? false;
|
|
293
|
+
return rawResults.map(result => {
|
|
294
|
+
const payload = result.metadata || {};
|
|
295
|
+
const system = payload.system || {};
|
|
296
|
+
// Convert timestamp to ISO string
|
|
297
|
+
const timestamp = system.createdAt || Date.now();
|
|
298
|
+
const createdAt = new Date(timestamp).toISOString();
|
|
299
|
+
const searchResult = {
|
|
300
|
+
id: result.id,
|
|
301
|
+
text: result.text,
|
|
302
|
+
score: result.score,
|
|
303
|
+
createdAt, // ISO 8601 datetime string
|
|
304
|
+
metadata: payload.metadata || {},
|
|
305
|
+
};
|
|
306
|
+
// Only include system metadata if explicitly requested
|
|
307
|
+
if (includeSystem) {
|
|
308
|
+
searchResult.system = system;
|
|
309
|
+
}
|
|
310
|
+
return searchResult;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
throw new types_1.VectorEmbeddingError(`Failed to search: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined, { query, options });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Update or insert a document (handles all chunks automatically)
|
|
319
|
+
*/
|
|
320
|
+
async upsert(collection, documentId, text, options) {
|
|
321
|
+
this.validateCollectionName(collection);
|
|
322
|
+
this.validateText(text);
|
|
323
|
+
try {
|
|
324
|
+
// Delete existing document and all its chunks
|
|
325
|
+
await this.delete(collection, documentId);
|
|
326
|
+
// Re-embed with same document ID
|
|
327
|
+
await this.embed(collection, text, { ...options, documentId });
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
throw new types_1.VectorEmbeddingError(`Failed to upsert document: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Delete a document and all its chunks
|
|
335
|
+
* Uses metadata filtering to find and delete all chunks efficiently
|
|
336
|
+
*/
|
|
337
|
+
async delete(collection, documentId) {
|
|
338
|
+
this.validateCollectionName(collection);
|
|
339
|
+
const documentIds = Array.isArray(documentId) ? documentId : [documentId];
|
|
340
|
+
if (documentIds.length === 0) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const allIds = [];
|
|
345
|
+
for (const docId of documentIds) {
|
|
346
|
+
// Add the document ID itself (for non-chunked docs)
|
|
347
|
+
allIds.push(docId);
|
|
348
|
+
// Query for all chunks with this documentId using metadata filter
|
|
349
|
+
// Chunks have system._documentId metadata set to the parent document ID
|
|
350
|
+
const chunkIds = await this.vectorStoreProvider.getIdsByFilter(collection, { 'system._documentId': docId });
|
|
351
|
+
allIds.push(...chunkIds);
|
|
352
|
+
}
|
|
353
|
+
// Delete all IDs (only actual existing ones)
|
|
354
|
+
if (allIds.length > 0) {
|
|
355
|
+
await this.vectorStoreProvider.delete(collection, allIds);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
throw new types_1.VectorStoreError(`Failed to delete document(s): ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Delete an entire collection
|
|
364
|
+
*/
|
|
365
|
+
async deleteCollection(collection) {
|
|
366
|
+
this.validateCollectionName(collection);
|
|
367
|
+
try {
|
|
368
|
+
await this.vectorStoreProvider.deleteCollection(collection);
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
throw new types_1.VectorStoreError(`Failed to delete collection: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Ensure a collection exists with optional custom configuration
|
|
376
|
+
*/
|
|
377
|
+
async ensureCollection(collection, config) {
|
|
378
|
+
this.validateCollectionName(collection);
|
|
379
|
+
try {
|
|
380
|
+
const dimension = config?.dimension ?? this.embeddingProvider.getDimension();
|
|
381
|
+
await this.vectorStoreProvider.ensureCollection(collection, dimension, config);
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
throw new types_1.VectorStoreError(`Failed to ensure collection: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : undefined);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Get the current embedding provider
|
|
389
|
+
*/
|
|
390
|
+
getEmbeddingProvider() {
|
|
391
|
+
return this.embeddingProvider;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get the current vector store provider
|
|
395
|
+
*/
|
|
396
|
+
getVectorStoreProvider() {
|
|
397
|
+
return this.vectorStoreProvider;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Generate chunk ID from document ID and chunk index
|
|
401
|
+
*/
|
|
402
|
+
static getChunkId(documentId, chunkIndex) {
|
|
403
|
+
return `${documentId}#${chunkIndex}`;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Parse chunk ID to extract document ID and chunk index
|
|
407
|
+
*/
|
|
408
|
+
static parseChunkId(chunkId) {
|
|
409
|
+
const parts = chunkId.split('#');
|
|
410
|
+
if (parts.length !== 2) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
const chunkIndex = parseInt(parts[1], 10);
|
|
414
|
+
if (isNaN(chunkIndex)) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
documentId: parts[0],
|
|
419
|
+
chunkIndex,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Check if an ID is a chunk ID (contains #)
|
|
424
|
+
*/
|
|
425
|
+
static isChunkId(id) {
|
|
426
|
+
return id.includes('#');
|
|
427
|
+
}
|
|
428
|
+
// Private methods
|
|
429
|
+
resolveEmbeddingProvider(config) {
|
|
430
|
+
if (config?.embeddingProvider) {
|
|
431
|
+
return config.embeddingProvider;
|
|
432
|
+
}
|
|
433
|
+
const embedding = config?.embedding;
|
|
434
|
+
if (!embedding) {
|
|
435
|
+
throw new types_1.VectorEmbeddingError('No embedding provider configured. Pass `embedding` or `embeddingProvider`.');
|
|
436
|
+
}
|
|
437
|
+
return this.createEmbeddingProviderFromRuntime(embedding);
|
|
438
|
+
}
|
|
439
|
+
resolveVectorStoreProvider(config) {
|
|
440
|
+
if (config?.vectorStoreProvider) {
|
|
441
|
+
return config.vectorStoreProvider;
|
|
442
|
+
}
|
|
443
|
+
const store = config?.store;
|
|
444
|
+
if (!store) {
|
|
445
|
+
return new sqlite_1.SQLiteVectorStoreProvider({
|
|
446
|
+
path: './vector.db',
|
|
447
|
+
inMemory: false,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
return this.createVectorStoreProviderFromRuntime(store);
|
|
451
|
+
}
|
|
452
|
+
createEmbeddingProviderFromRuntime(config) {
|
|
453
|
+
if (config.type === 'custom') {
|
|
454
|
+
return config.provider;
|
|
455
|
+
}
|
|
456
|
+
return new openai_1.OpenAIEmbeddingProvider({
|
|
457
|
+
apiKey: config.apiKey,
|
|
458
|
+
model: config.model || 'text-embedding-3-small',
|
|
459
|
+
dimension: config.dimension,
|
|
460
|
+
maxRetries: config.maxRetries,
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
createVectorStoreProviderFromRuntime(config) {
|
|
464
|
+
switch (config.type) {
|
|
465
|
+
case 'sqlite': {
|
|
466
|
+
const sqlitePath = config.path || './vector.db';
|
|
467
|
+
return new sqlite_1.SQLiteVectorStoreProvider({
|
|
468
|
+
path: sqlitePath,
|
|
469
|
+
inMemory: sqlitePath === ':memory:',
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
case 'qdrant':
|
|
473
|
+
return new qdrant_1.QdrantVectorStoreProvider({
|
|
474
|
+
url: config.url,
|
|
475
|
+
apiKey: config.apiKey,
|
|
476
|
+
port: config.port,
|
|
477
|
+
timeout: config.timeout,
|
|
478
|
+
checkCompatibility: config.checkCompatibility,
|
|
479
|
+
});
|
|
480
|
+
case 'memory':
|
|
481
|
+
return new memory_1.InMemoryVectorStoreProvider();
|
|
482
|
+
case 'custom':
|
|
483
|
+
return config.provider;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
validateCollectionName(name) {
|
|
487
|
+
if (!name || typeof name !== 'string') {
|
|
488
|
+
throw new types_1.VectorStoreError('Collection name must be a non-empty string');
|
|
489
|
+
}
|
|
490
|
+
// Collection names should be alphanumeric with underscores and hyphens
|
|
491
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
|
|
492
|
+
throw new types_1.VectorStoreError('Collection name must contain only alphanumeric characters, underscores, and hyphens');
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
validateText(text) {
|
|
496
|
+
if (!text || typeof text !== 'string') {
|
|
497
|
+
throw new types_1.VectorEmbeddingError('Text must be a non-empty string');
|
|
498
|
+
}
|
|
499
|
+
if (text.trim().length === 0) {
|
|
500
|
+
throw new types_1.VectorEmbeddingError('Text cannot be empty or only whitespace');
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
exports.Vector = Vector;
|
|
505
|
+
//# sourceMappingURL=vector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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