@vibe-agent-toolkit/rag-lancedb 0.1.0-rc.7

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 ADDED
@@ -0,0 +1,122 @@
1
+ # @vibe-agent-toolkit/rag-lancedb
2
+
3
+ LanceDB implementation of RAG interfaces for vibe-agent-toolkit.
4
+
5
+ ## Overview
6
+
7
+ This package provides a complete RAG (Retrieval-Augmented Generation) implementation using LanceDB as the vector database. It implements both `RAGQueryProvider` (read-only) and `RAGAdminProvider` (read/write) interfaces.
8
+
9
+ **Features:**
10
+ - Local file-based vector database (no server required)
11
+ - Fast vector search with LanceDB
12
+ - Resource-level change detection (content hashing)
13
+ - Readonly and admin modes
14
+ - Persistent storage with Apache Arrow
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ bun add @vibe-agent-toolkit/rag-lancedb
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### Building a RAG Database
25
+
26
+ ```typescript
27
+ import { LanceDBRAGProvider } from '@vibe-agent-toolkit/rag-lancedb';
28
+ import { TransformersEmbeddingProvider } from '@vibe-agent-toolkit/rag';
29
+ import { ResourceRegistry } from '@vibe-agent-toolkit/resources';
30
+
31
+ // 1. Scan resources
32
+ const registry = new ResourceRegistry();
33
+ await registry.crawl({ baseDir: './docs' });
34
+
35
+ // 2. Create admin provider
36
+ const admin = await LanceDBRAGProvider.create({
37
+ dbPath: './rag-db',
38
+ embeddingProvider: new TransformersEmbeddingProvider(),
39
+ });
40
+
41
+ // 3. Index resources
42
+ const result = await admin.indexResources(registry.getAllResources());
43
+ console.log(`Indexed ${result.chunksCreated} chunks`);
44
+
45
+ await admin.close();
46
+ ```
47
+
48
+ ### Querying a RAG Database
49
+
50
+ ```typescript
51
+ import { LanceDBRAGProvider } from '@vibe-agent-toolkit/rag-lancedb';
52
+
53
+ // Open in readonly mode (for agents)
54
+ const rag = await LanceDBRAGProvider.create({
55
+ dbPath: './rag-db',
56
+ readonly: true,
57
+ });
58
+
59
+ // Query
60
+ const result = await rag.query({
61
+ text: 'How do I validate schemas?',
62
+ limit: 5,
63
+ filters: {
64
+ tags: ['validation'],
65
+ },
66
+ });
67
+
68
+ // Use results
69
+ for (const chunk of result.chunks) {
70
+ console.log(`[${chunk.headingPath}] ${chunk.content}`);
71
+ }
72
+ ```
73
+
74
+ ## Architecture
75
+
76
+ - **Database**: LanceDB (Apache Arrow format)
77
+ - **Storage**: Local file-based (`.lance` directory)
78
+ - **Change Detection**: Content hashing (SHA-256)
79
+ - **Updates**: Resource-level (delete old chunks, re-embed new)
80
+
81
+ ## Known Issues
82
+
83
+ ### Bun + vectordb@0.4.x Arrow Buffer Detachment
84
+
85
+ **Issue**: When running under Bun runtime with `vectordb@0.4.20`, Apache Arrow buffers can become detached after table modifications (add/delete operations), causing "Buffer is already detached" errors on subsequent queries. This primarily affects rapid multi-resource indexing operations in short-lived test scenarios.
86
+
87
+ **Technical Details**:
88
+ - **Root Cause**: Apache Arrow uses zero-copy memory buffers for performance. When LanceDB performs table modifications, these buffers can be garbage collected or invalidated before subsequent queries can access them. Bun's garbage collector appears to be more aggressive than Node.js in reclaiming these buffers.
89
+ - **Trigger**: Indexing multiple resources in rapid succession, then querying the database in the same connection lifecycle
90
+ - **Error**: `TypeError: Buffer is already detached` when calling `.execute()` on query results
91
+
92
+ **Workarounds Implemented**:
93
+ 1. **Connection Recreation**: Before each query/stats operation, we recreate the database connection entirely (`connect()` + `openTable()`)
94
+ 2. **Immediate Materialization**: Results are materialized using `JSON.parse(JSON.stringify())` immediately after query execution to copy data out of Arrow buffers before they're invalidated
95
+ 3. **Data Extraction Before Modifications**: When checking for existing resources during indexing, we extract all needed data from Arrow buffers before performing any table modifications
96
+
97
+ **Production Impact**: **Minimal**
98
+ - Production usage typically involves long-lived provider connections where this issue doesn't manifest
99
+ - Single-resource operations work reliably
100
+ - Query operations (the most common in production) are stable after the connection recreation workaround
101
+
102
+ **Test Impact**: **Significant**
103
+ - 18 integration and system tests are skipped due to this issue
104
+ - Tests that index multiple resources in rapid succession fail consistently
105
+ - Single-resource tests pass reliably
106
+
107
+ **Resolution Options**:
108
+ 1. **Upgrade LanceDB**: Wait for newer versions of `vectordb` that may have fixed this issue (current: ^0.4.0)
109
+ 2. **Use Node.js**: Run tests with Node.js instead of Bun (the issue is Bun-specific)
110
+ 3. **Accept Limitation**: Document and skip affected tests, as production usage is unaffected
111
+
112
+ **Why Not Use `structuredClone()`?**
113
+ The standard `structuredClone()` function doesn't work with Arrow buffers because they contain native memory references that can't be cloned. `JSON.parse(JSON.stringify())` forces full serialization/deserialization, creating new JavaScript objects completely independent of Arrow's memory management.
114
+
115
+ **References**:
116
+ - Issue affects: `packages/rag-lancedb/src/lancedb-rag-provider.ts` (see comments at lines 107, 138, 198, 220, 282, 289)
117
+ - Skipped tests: `packages/rag-lancedb/test/integration/indexing.integration.test.ts`
118
+ - Skipped system tests: `packages/rag-lancedb/test/system/lancedb-rag-provider.system.test.ts`
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @vibe-agent-toolkit/rag-lancedb
3
+ *
4
+ * LanceDB implementation of RAG interfaces for vibe-agent-toolkit.
5
+ */
6
+ export { LanceDBRAGProvider, type LanceDBConfig } from './lancedb-rag-provider.js';
7
+ export { chunkToLanceRow, lanceRowToChunk, type LanceDBRow } from './schema.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @vibe-agent-toolkit/rag-lancedb
3
+ *
4
+ * LanceDB implementation of RAG interfaces for vibe-agent-toolkit.
5
+ */
6
+ export { LanceDBRAGProvider } from './lancedb-rag-provider.js';
7
+ export { chunkToLanceRow, lanceRowToChunk } from './schema.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAsB,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * LanceDB RAG Provider
3
+ *
4
+ * Implements both RAGQueryProvider and RAGAdminProvider using LanceDB.
5
+ */
6
+ import type { EmbeddingProvider, IndexResult, RAGAdminProvider, RAGQuery, RAGResult, RAGStats } from '@vibe-agent-toolkit/rag';
7
+ import { type ResourceMetadata } from '@vibe-agent-toolkit/resources';
8
+ /**
9
+ * Configuration for LanceDBRAGProvider
10
+ */
11
+ export interface LanceDBConfig {
12
+ /** Path to LanceDB database directory */
13
+ dbPath: string;
14
+ /** Readonly mode (query only) */
15
+ readonly?: boolean;
16
+ /** Embedding provider (default: TransformersEmbeddingProvider) */
17
+ embeddingProvider?: EmbeddingProvider;
18
+ /** Target chunk size in tokens (default: 512) */
19
+ targetChunkSize?: number;
20
+ /** Padding factor for token estimation (default: 0.9) */
21
+ paddingFactor?: number;
22
+ }
23
+ /**
24
+ * LanceDBRAGProvider
25
+ *
26
+ * Complete RAG implementation using LanceDB for vector storage.
27
+ */
28
+ export declare class LanceDBRAGProvider implements RAGAdminProvider {
29
+ private readonly config;
30
+ private connection;
31
+ private table;
32
+ private readonly tokenCounter;
33
+ private constructor();
34
+ /**
35
+ * Create and initialize LanceDBRAGProvider
36
+ *
37
+ * @param config - Configuration
38
+ * @returns Initialized provider
39
+ */
40
+ static create(config: LanceDBConfig): Promise<LanceDBRAGProvider>;
41
+ /**
42
+ * Initialize database connection and table
43
+ */
44
+ private initialize;
45
+ /**
46
+ * Query the RAG database
47
+ */
48
+ query(query: RAGQuery): Promise<RAGResult>;
49
+ /**
50
+ * Build WHERE clause from filters
51
+ */
52
+ private buildWhereClause;
53
+ /**
54
+ * Get database statistics
55
+ */
56
+ getStats(): Promise<RAGStats>;
57
+ /**
58
+ * Index resources into the RAG database
59
+ */
60
+ indexResources(resources: ResourceMetadata[]): Promise<IndexResult>;
61
+ /**
62
+ * Index a single resource
63
+ */
64
+ private indexResource;
65
+ /**
66
+ * Update a specific resource
67
+ */
68
+ updateResource(_resourceId: string): Promise<void>;
69
+ /**
70
+ * Delete a specific resource and all its chunks
71
+ *
72
+ * @param resourceId - ID of resource to delete
73
+ */
74
+ deleteResource(resourceId: string): Promise<void>;
75
+ /**
76
+ * Clear the entire database
77
+ *
78
+ * Deletes all data and removes the database directory.
79
+ * This is a destructive operation that cannot be undone.
80
+ */
81
+ clear(): Promise<void>;
82
+ /**
83
+ * Close database connection
84
+ */
85
+ close(): Promise<void>;
86
+ }
87
+ //# sourceMappingURL=lancedb-rag-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lancedb-rag-provider.d.ts","sourceRoot":"","sources":["../src/lancedb-rag-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAEhB,QAAQ,EACR,SAAS,EACT,QAAQ,EACT,MAAM,yBAAyB,CAAC;AAQjC,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAMrF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IAEf,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IACzD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,KAAK,CAAkC;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiC;IAE9D,OAAO;IAUP;;;;;OAKG;WACU,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAMvE;;OAEG;YACW,UAAU;IAcxB;;OAEG;IACG,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAqDhD;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgCxB;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC;IAqCnC;;OAEG;IACG,cAAc,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IA+BzE;;OAEG;YACW,aAAa;IAqG3B;;OAEG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAavD;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAe5B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -0,0 +1,319 @@
1
+ /**
2
+ * LanceDB RAG Provider
3
+ *
4
+ * Implements both RAGQueryProvider and RAGAdminProvider using LanceDB.
5
+ */
6
+ import fs from 'node:fs';
7
+ import { ApproximateTokenCounter, chunkResource, enrichChunks, generateContentHash, TransformersEmbeddingProvider, } from '@vibe-agent-toolkit/rag';
8
+ import { parseMarkdown } from '@vibe-agent-toolkit/resources';
9
+ import { connect } from 'vectordb';
10
+ import { chunkToLanceRow, lanceRowToChunk } from './schema.js';
11
+ const TABLE_NAME = 'rag_chunks';
12
+ /**
13
+ * LanceDBRAGProvider
14
+ *
15
+ * Complete RAG implementation using LanceDB for vector storage.
16
+ */
17
+ export class LanceDBRAGProvider {
18
+ config;
19
+ connection = null;
20
+ table = null;
21
+ tokenCounter = new ApproximateTokenCounter();
22
+ constructor(config) {
23
+ this.config = {
24
+ readonly: false,
25
+ embeddingProvider: new TransformersEmbeddingProvider(),
26
+ targetChunkSize: 512,
27
+ paddingFactor: 0.9,
28
+ ...config,
29
+ };
30
+ }
31
+ /**
32
+ * Create and initialize LanceDBRAGProvider
33
+ *
34
+ * @param config - Configuration
35
+ * @returns Initialized provider
36
+ */
37
+ static async create(config) {
38
+ const provider = new LanceDBRAGProvider(config);
39
+ await provider.initialize();
40
+ return provider;
41
+ }
42
+ /**
43
+ * Initialize database connection and table
44
+ */
45
+ async initialize() {
46
+ this.connection = await connect(this.config.dbPath);
47
+ const tableNames = await this.connection.tableNames();
48
+ if (tableNames.includes(TABLE_NAME)) {
49
+ this.table = await this.connection.openTable(TABLE_NAME);
50
+ }
51
+ else {
52
+ // Table doesn't exist
53
+ // In admin mode: will be created on first insert
54
+ // In readonly mode: operations that require table will fail gracefully
55
+ this.table = null;
56
+ }
57
+ }
58
+ /**
59
+ * Query the RAG database
60
+ */
61
+ async query(query) {
62
+ // Workaround for vectordb@0.4.20 + Bun Arrow buffer lifecycle bug
63
+ // After table modifications, we need to recreate the connection entirely
64
+ this.connection = await connect(this.config.dbPath);
65
+ const tableNames = await this.connection.tableNames();
66
+ if (!tableNames.includes(TABLE_NAME)) {
67
+ throw new Error('No data indexed yet');
68
+ }
69
+ this.table = (await this.connection.openTable(TABLE_NAME));
70
+ if (!this.table) {
71
+ throw new Error('No data indexed yet');
72
+ }
73
+ const startTime = Date.now();
74
+ // Embed query text
75
+ const queryEmbedding = await this.config.embeddingProvider.embed(query.text);
76
+ // Perform vector search
77
+ let search = this.table.search(queryEmbedding).limit(query.limit ?? 10);
78
+ // Apply filters if provided
79
+ if (query.filters) {
80
+ const whereClause = this.buildWhereClause(query.filters);
81
+ if (whereClause) {
82
+ search = search.where(whereClause);
83
+ }
84
+ }
85
+ const results = await search.execute();
86
+ // Convert results to plain objects immediately to avoid Arrow buffer issues
87
+ // eslint-disable-next-line unicorn/prefer-structured-clone -- JSON.parse/stringify is intentional workaround for Arrow buffer lifecycle bug
88
+ const materializedResults = JSON.parse(JSON.stringify(results));
89
+ // Convert results to RAGChunks
90
+ const chunks = materializedResults.map((row) => lanceRowToChunk(row));
91
+ const searchDurationMs = Date.now() - startTime;
92
+ return {
93
+ chunks,
94
+ stats: {
95
+ totalMatches: chunks.length,
96
+ searchDurationMs,
97
+ embedding: {
98
+ model: this.config.embeddingProvider.model,
99
+ },
100
+ },
101
+ };
102
+ }
103
+ /**
104
+ * Build WHERE clause from filters
105
+ */
106
+ buildWhereClause(filters) {
107
+ if (!filters) {
108
+ return null;
109
+ }
110
+ const conditions = [];
111
+ if (filters.resourceId !== undefined) {
112
+ const ids = Array.isArray(filters.resourceId) ? filters.resourceId : [filters.resourceId];
113
+ // Handle empty array case - should match nothing
114
+ if (ids.length === 0) {
115
+ conditions.push('1 = 0'); // Always false condition
116
+ }
117
+ else {
118
+ const idList = ids.map((id) => `'${id}'`).join(', ');
119
+ // Use backticks for column names
120
+ conditions.push(`\`resourceId\` IN (${idList})`);
121
+ }
122
+ }
123
+ if (filters.type) {
124
+ conditions.push(`type = '${filters.type}'`);
125
+ }
126
+ if (filters.headingPath) {
127
+ // Use backticks for column names
128
+ conditions.push(`\`headingPath\` = '${filters.headingPath}'`);
129
+ }
130
+ return conditions.length > 0 ? conditions.join(' AND ') : null;
131
+ }
132
+ /**
133
+ * Get database statistics
134
+ */
135
+ async getStats() {
136
+ // Workaround for vectordb@0.4.20 + Bun Arrow buffer lifecycle bug
137
+ // After table modifications, we need to recreate the connection entirely
138
+ this.connection = await connect(this.config.dbPath);
139
+ const tableNames = await this.connection.tableNames();
140
+ if (tableNames.includes(TABLE_NAME)) {
141
+ this.table = (await this.connection.openTable(TABLE_NAME));
142
+ }
143
+ if (!this.table) {
144
+ return {
145
+ totalChunks: 0,
146
+ totalResources: 0,
147
+ dbSizeBytes: 0,
148
+ embeddingModel: this.config.embeddingProvider.model,
149
+ lastIndexed: new Date(0),
150
+ };
151
+ }
152
+ const count = await this.table.countRows();
153
+ // Get unique resource count (use a condition that matches all rows)
154
+ const allRows = await this.table.filter('1 = 1').execute();
155
+ // Materialize immediately to avoid Arrow buffer issues
156
+ // eslint-disable-next-line unicorn/prefer-structured-clone -- JSON.parse/stringify is intentional workaround for Arrow buffer lifecycle bug
157
+ const rows = JSON.parse(JSON.stringify(allRows));
158
+ const uniqueResources = new Set(rows.map((r) => r.resourceId)).size;
159
+ return {
160
+ totalChunks: count,
161
+ totalResources: uniqueResources,
162
+ dbSizeBytes: 0, // LanceDB doesn't provide size info easily
163
+ embeddingModel: this.config.embeddingProvider.model,
164
+ lastIndexed: new Date(), // Would need to track this separately
165
+ };
166
+ }
167
+ /**
168
+ * Index resources into the RAG database
169
+ */
170
+ async indexResources(resources) {
171
+ if (this.config.readonly) {
172
+ throw new Error('Cannot index in readonly mode');
173
+ }
174
+ const startTime = Date.now();
175
+ const result = {
176
+ resourcesIndexed: 0,
177
+ resourcesSkipped: 0,
178
+ resourcesUpdated: 0,
179
+ chunksCreated: 0,
180
+ chunksDeleted: 0,
181
+ durationMs: 0,
182
+ errors: [],
183
+ };
184
+ for (const resource of resources) {
185
+ try {
186
+ await this.indexResource(resource, result);
187
+ }
188
+ catch (error) {
189
+ result.errors?.push({
190
+ resourceId: resource.id,
191
+ error: error instanceof Error ? error.message : String(error),
192
+ });
193
+ }
194
+ }
195
+ result.durationMs = Date.now() - startTime;
196
+ return result;
197
+ }
198
+ /**
199
+ * Index a single resource
200
+ */
201
+ async indexResource(resource, result) {
202
+ // Read file content using parseMarkdown
203
+ const parseResult = await parseMarkdown(resource.filePath);
204
+ // Generate content hash for change detection
205
+ const resourceContentHash = generateContentHash(parseResult.content);
206
+ // Check if resource already exists with same content hash
207
+ // Extract all needed data BEFORE any table modifications to avoid Arrow buffer issues
208
+ let shouldSkip = false;
209
+ let deleteCount = 0;
210
+ let shouldUpdate = false;
211
+ if (this.table) {
212
+ const existingRows = await this.table.filter(`\`resourceId\` = '${resource.id}'`).execute();
213
+ // Materialize immediately to avoid Arrow buffer issues
214
+ // eslint-disable-next-line unicorn/prefer-structured-clone -- JSON.parse/stringify is intentional workaround for Arrow buffer lifecycle bug
215
+ const existing = JSON.parse(JSON.stringify(existingRows));
216
+ // Extract data immediately while Arrow buffers are valid
217
+ if (existing.length > 0) {
218
+ const existingHash = existing[0]?.resourceContentHash;
219
+ deleteCount = existing.length;
220
+ if (existingHash === resourceContentHash) {
221
+ shouldSkip = true;
222
+ }
223
+ else {
224
+ shouldUpdate = true;
225
+ }
226
+ }
227
+ }
228
+ // Handle skip case
229
+ if (shouldSkip) {
230
+ result.resourcesSkipped++;
231
+ return;
232
+ }
233
+ // Delete old chunks if updating
234
+ if (shouldUpdate) {
235
+ await this.deleteResource(resource.id);
236
+ result.chunksDeleted += deleteCount;
237
+ result.resourcesUpdated++;
238
+ }
239
+ // Chunk the resource
240
+ const chunkingResult = chunkResource({
241
+ ...resource,
242
+ content: parseResult.content,
243
+ frontmatter: {},
244
+ }, {
245
+ targetChunkSize: this.config.targetChunkSize,
246
+ modelTokenLimit: 8191,
247
+ paddingFactor: this.config.paddingFactor,
248
+ tokenCounter: this.tokenCounter,
249
+ });
250
+ // Embed chunks
251
+ const embeddings = await this.config.embeddingProvider.embedBatch(chunkingResult.chunks.map((c) => c.content));
252
+ // Enrich chunks with full metadata
253
+ const chunkableResource = {
254
+ ...resource,
255
+ content: parseResult.content,
256
+ frontmatter: {},
257
+ };
258
+ const ragChunks = enrichChunks(chunkingResult.chunks, chunkableResource, embeddings, this.config.embeddingProvider.model);
259
+ // Convert to LanceDB rows
260
+ const rows = ragChunks.map((chunk) => chunkToLanceRow(chunk, resourceContentHash));
261
+ // Insert into LanceDB
262
+ if (!this.table && this.connection) {
263
+ this.table = (await this.connection.createTable(TABLE_NAME, rows));
264
+ }
265
+ else if (this.table) {
266
+ await this.table.add(rows);
267
+ }
268
+ result.resourcesIndexed++;
269
+ result.chunksCreated += rows.length;
270
+ }
271
+ /**
272
+ * Update a specific resource
273
+ */
274
+ async updateResource(_resourceId) {
275
+ throw new Error('Not implemented - use indexResources() instead');
276
+ }
277
+ /**
278
+ * Delete a specific resource and all its chunks
279
+ *
280
+ * @param resourceId - ID of resource to delete
281
+ */
282
+ async deleteResource(resourceId) {
283
+ if (this.config.readonly) {
284
+ throw new Error('Cannot delete in readonly mode');
285
+ }
286
+ if (!this.table) {
287
+ return;
288
+ }
289
+ // Delete chunks (use backticks for column names)
290
+ await this.table.delete(`\`resourceId\` = '${resourceId}'`);
291
+ }
292
+ /**
293
+ * Clear the entire database
294
+ *
295
+ * Deletes all data and removes the database directory.
296
+ * This is a destructive operation that cannot be undone.
297
+ */
298
+ async clear() {
299
+ if (this.config.readonly) {
300
+ throw new Error('Cannot clear in readonly mode');
301
+ }
302
+ // Close connection first
303
+ await this.close();
304
+ // Delete entire database directory
305
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- dbPath comes from validated config
306
+ if (fs.existsSync(this.config.dbPath)) {
307
+ fs.rmSync(this.config.dbPath, { recursive: true, force: true });
308
+ }
309
+ }
310
+ /**
311
+ * Close database connection
312
+ */
313
+ async close() {
314
+ // LanceDB connections are automatically managed
315
+ this.connection = null;
316
+ this.table = null;
317
+ }
318
+ }
319
+ //# sourceMappingURL=lancedb-rag-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lancedb-rag-provider.js","sourceRoot":"","sources":["../src/lancedb-rag-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AAWzB,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,YAA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;YACzB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QAED,yBAAyB;QACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QAEnB,mCAAmC;QACnC,yGAAyG;QACzG,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,gDAAgD;QAChD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * LanceDB schema mapping
3
+ *
4
+ * Converts between RAGChunk and LanceDB row format.
5
+ */
6
+ import type { RAGChunk } from '@vibe-agent-toolkit/rag';
7
+ /**
8
+ * LanceDB row format
9
+ *
10
+ * LanceDB stores data in Apache Arrow format with specific type requirements.
11
+ * Must have index signature for LanceDB compatibility.
12
+ *
13
+ * Note: LanceDB/Arrow cannot infer array types if all values are null,
14
+ * so we use empty arrays instead of null for array fields.
15
+ */
16
+ export interface LanceDBRow extends Record<string, unknown> {
17
+ vector: number[];
18
+ chunkId: string;
19
+ resourceId: string;
20
+ content: string;
21
+ contentHash: string;
22
+ resourceContentHash: string;
23
+ tokenCount: number;
24
+ headingPath: string;
25
+ headingLevel: number | null;
26
+ startLine: number | null;
27
+ endLine: number | null;
28
+ filePath: string;
29
+ tags: string;
30
+ type: string;
31
+ title: string;
32
+ embeddingModel: string;
33
+ embeddedAt: number;
34
+ previousChunkId: string;
35
+ nextChunkId: string;
36
+ }
37
+ /**
38
+ * Convert RAGChunk to LanceDB row format
39
+ *
40
+ * @param chunk - RAGChunk to convert
41
+ * @param resourceContentHash - Hash of the full resource content (for change detection)
42
+ * @returns LanceDB row
43
+ */
44
+ export declare function chunkToLanceRow(chunk: RAGChunk, resourceContentHash: string): LanceDBRow;
45
+ /**
46
+ * Convert LanceDB row to RAGChunk
47
+ *
48
+ * @param row - LanceDB row
49
+ * @returns RAGChunk
50
+ */
51
+ export declare function lanceRowToChunk(row: LanceDBRow): RAGChunk;
52
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAW,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEzD,MAAM,EAAE,MAAM,EAAE,CAAC;IAGjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IAGnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAGvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IAGd,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IAGnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,GAAG,UAAU,CAsBxF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,GAAG,QAAQ,CA2BzD"}
package/dist/schema.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * LanceDB schema mapping
3
+ *
4
+ * Converts between RAGChunk and LanceDB row format.
5
+ */
6
+ /**
7
+ * Convert RAGChunk to LanceDB row format
8
+ *
9
+ * @param chunk - RAGChunk to convert
10
+ * @param resourceContentHash - Hash of the full resource content (for change detection)
11
+ * @returns LanceDB row
12
+ */
13
+ export function chunkToLanceRow(chunk, resourceContentHash) {
14
+ return {
15
+ vector: chunk.embedding,
16
+ chunkId: chunk.chunkId,
17
+ resourceId: chunk.resourceId,
18
+ content: chunk.content,
19
+ contentHash: chunk.contentHash,
20
+ resourceContentHash,
21
+ tokenCount: chunk.tokenCount,
22
+ headingPath: chunk.headingPath ?? '', // Empty string for Arrow
23
+ headingLevel: chunk.headingLevel ?? null,
24
+ startLine: chunk.startLine ?? null,
25
+ endLine: chunk.endLine ?? null,
26
+ filePath: chunk.filePath,
27
+ tags: chunk.tags?.join(',') ?? '', // Convert array to comma-separated string
28
+ type: chunk.type ?? '', // Empty string for Arrow
29
+ title: chunk.title ?? '', // Empty string for Arrow
30
+ embeddingModel: chunk.embeddingModel,
31
+ embeddedAt: chunk.embeddedAt.getTime(),
32
+ previousChunkId: chunk.previousChunkId ?? '', // Empty string for Arrow
33
+ nextChunkId: chunk.nextChunkId ?? '', // Empty string for Arrow
34
+ };
35
+ }
36
+ /**
37
+ * Convert LanceDB row to RAGChunk
38
+ *
39
+ * @param row - LanceDB row
40
+ * @returns RAGChunk
41
+ */
42
+ export function lanceRowToChunk(row) {
43
+ const chunk = {
44
+ chunkId: row.chunkId,
45
+ resourceId: row.resourceId,
46
+ content: row.content,
47
+ contentHash: row.contentHash,
48
+ tokenCount: row.tokenCount,
49
+ filePath: row.filePath,
50
+ embedding: row.vector,
51
+ embeddingModel: row.embeddingModel,
52
+ embeddedAt: new Date(row.embeddedAt),
53
+ };
54
+ // Only add optional properties if they exist (non-empty strings)
55
+ if (row.headingPath && row.headingPath.length > 0)
56
+ chunk.headingPath = row.headingPath;
57
+ if (row.headingLevel !== null)
58
+ chunk.headingLevel = row.headingLevel;
59
+ if (row.startLine !== null)
60
+ chunk.startLine = row.startLine;
61
+ if (row.endLine !== null)
62
+ chunk.endLine = row.endLine;
63
+ if (row.tags && row.tags.length > 0) {
64
+ chunk.tags = row.tags.split(','); // Convert comma-separated string back to array
65
+ }
66
+ if (row.type && row.type.length > 0)
67
+ chunk.type = row.type;
68
+ if (row.title && row.title.length > 0)
69
+ chunk.title = row.title;
70
+ if (row.previousChunkId && row.previousChunkId.length > 0)
71
+ chunk.previousChunkId = row.previousChunkId;
72
+ if (row.nextChunkId && row.nextChunkId.length > 0)
73
+ chunk.nextChunkId = row.nextChunkId;
74
+ return chunk;
75
+ }
76
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8CH;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAe,EAAE,mBAA2B;IAC1E,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,SAAS;QACvB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,mBAAmB;QACnB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,EAAE,EAAE,yBAAyB;QAC/D,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,IAAI;QACxC,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI;QAClC,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI;QAC9B,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AAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;IAC5D,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI;QAAE,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IACtD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,+CAA+C;IACnF,CAAC;IACD,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;IAC3D,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IAC/D,IAAI,GAAG,CAAC,eAAe,IAAI,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC,eAAe,CAAC;IACvG,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;IAEvF,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@vibe-agent-toolkit/rag-lancedb",
3
+ "version": "0.1.0-rc.7",
4
+ "type": "module",
5
+ "description": "LanceDB implementation of RAG interfaces for vibe-agent-toolkit",
6
+ "keywords": [
7
+ "rag",
8
+ "vector-search",
9
+ "lancedb",
10
+ "embeddings"
11
+ ],
12
+ "author": "Jeff Dutton",
13
+ "license": "MIT",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "clean": "rimraf dist",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "test:integration": "vitest run --config vitest.integration.config.ts",
32
+ "test:system": "vitest run --config vitest.system.config.ts",
33
+ "typecheck": "tsc --noEmit"
34
+ },
35
+ "dependencies": {
36
+ "@vibe-agent-toolkit/rag": "workspace:*",
37
+ "@vibe-agent-toolkit/resources": "workspace:*",
38
+ "@vibe-agent-toolkit/utils": "workspace:*",
39
+ "vectordb": "^0.4.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.0.0",
43
+ "typescript": "^5.9.0",
44
+ "vitest": "^3.2.0"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/jdutton/vibe-agent-toolkit.git"
49
+ }
50
+ }