codeseeker 1.9.0 → 1.11.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/README.md +14 -2
- package/dist/cli/commands/services/semantic-search-orchestrator.d.ts +21 -1
- package/dist/cli/commands/services/semantic-search-orchestrator.d.ts.map +1 -1
- package/dist/cli/commands/services/semantic-search-orchestrator.js +189 -52
- package/dist/cli/commands/services/semantic-search-orchestrator.js.map +1 -1
- package/dist/cli/services/search/raptor-indexing-service.d.ts +83 -0
- package/dist/cli/services/search/raptor-indexing-service.d.ts.map +1 -0
- package/dist/cli/services/search/raptor-indexing-service.js +403 -0
- package/dist/cli/services/search/raptor-indexing-service.js.map +1 -0
- package/dist/mcp/indexing-service.d.ts +1 -1
- package/dist/mcp/indexing-service.d.ts.map +1 -1
- package/dist/mcp/indexing-service.js +25 -0
- package/dist/mcp/indexing-service.js.map +1 -1
- package/dist/mcp/mcp-server.d.ts.map +1 -1
- package/dist/mcp/mcp-server.js +13 -2
- package/dist/mcp/mcp-server.js.map +1 -1
- package/dist/storage/embedded/sqlite-vector-store.d.ts +4 -0
- package/dist/storage/embedded/sqlite-vector-store.d.ts.map +1 -1
- package/dist/storage/embedded/sqlite-vector-store.js +57 -17
- package/dist/storage/embedded/sqlite-vector-store.js.map +1 -1
- package/dist/storage/interfaces.d.ts +19 -0
- package/dist/storage/interfaces.d.ts.map +1 -1
- package/dist/storage/server/postgres-vector-store.d.ts +4 -0
- package/dist/storage/server/postgres-vector-store.d.ts.map +1 -1
- package/dist/storage/server/postgres-vector-store.js +60 -0
- package/dist/storage/server/postgres-vector-store.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RAPTOR Hierarchical Indexing Service
|
|
4
|
+
*
|
|
5
|
+
* A code-native variant of RAPTOR (Recursive Abstractive Processing for
|
|
6
|
+
* Tree-Organized Retrieval) that exploits the natural hierarchy of source code:
|
|
7
|
+
*
|
|
8
|
+
* chunk (file segment) → file → L2 (directory node) → L3 (root node)
|
|
9
|
+
*
|
|
10
|
+
* L2 nodes are created by mean-pooling the embeddings of all chunks within a
|
|
11
|
+
* directory, placing the node at the semantic centroid of that directory's content.
|
|
12
|
+
* No Claude CLI calls are needed — the centroid is computed from embeddings that
|
|
13
|
+
* already exist in the vector store.
|
|
14
|
+
*
|
|
15
|
+
* L3 is the mean of all L2 embeddings, representing the entire project.
|
|
16
|
+
*
|
|
17
|
+
* During search, L2/L3 nodes live in the same vector store as regular chunks.
|
|
18
|
+
* They surface naturally for abstract queries ("what does the auth package do?")
|
|
19
|
+
* and are invisible for concrete queries ("find the JWT refresh function").
|
|
20
|
+
*
|
|
21
|
+
* Incremental drift detection (used during sync):
|
|
22
|
+
* 1. Structural hash (sha256 of sorted child file paths) — detects file additions/deletions
|
|
23
|
+
* 2. Cosine distance between new pooled mean and stored RAPTOR embedding —
|
|
24
|
+
* skips the update when drift is below DRIFT_SKIP_THRESHOLD
|
|
25
|
+
*/
|
|
26
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
27
|
+
if (k2 === undefined) k2 = k;
|
|
28
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
29
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
30
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(o, k2, desc);
|
|
33
|
+
}) : (function(o, m, k, k2) {
|
|
34
|
+
if (k2 === undefined) k2 = k;
|
|
35
|
+
o[k2] = m[k];
|
|
36
|
+
}));
|
|
37
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
38
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
39
|
+
}) : function(o, v) {
|
|
40
|
+
o["default"] = v;
|
|
41
|
+
});
|
|
42
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
43
|
+
var ownKeys = function(o) {
|
|
44
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
45
|
+
var ar = [];
|
|
46
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
47
|
+
return ar;
|
|
48
|
+
};
|
|
49
|
+
return ownKeys(o);
|
|
50
|
+
};
|
|
51
|
+
return function (mod) {
|
|
52
|
+
if (mod && mod.__esModule) return mod;
|
|
53
|
+
var result = {};
|
|
54
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
55
|
+
__setModuleDefault(result, mod);
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
})();
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.RaptorIndexingService = exports.RAPTOR_FILE_PREFIX = void 0;
|
|
61
|
+
const path = __importStar(require("path"));
|
|
62
|
+
const crypto = __importStar(require("crypto"));
|
|
63
|
+
const logger_1 = require("../../../utils/logger");
|
|
64
|
+
// All RAPTOR node filePaths are prefixed so they are trivially distinguishable
|
|
65
|
+
// from real source file paths throughout the codebase.
|
|
66
|
+
exports.RAPTOR_FILE_PREFIX = '__raptor__/';
|
|
67
|
+
/** Minimum indexed files in a directory to create an L2 node */
|
|
68
|
+
const MIN_FILES_FOR_L2 = 2;
|
|
69
|
+
/** Minimum L2 nodes to create an L3 root node */
|
|
70
|
+
const MIN_L2_FOR_L3 = 3;
|
|
71
|
+
/**
|
|
72
|
+
* Cosine *distance* (1 − similarity) below which a RAPTOR node is NOT regenerated.
|
|
73
|
+
* 0.05 means "less than 5% semantic drift" → skip.
|
|
74
|
+
*/
|
|
75
|
+
const DRIFT_SKIP_THRESHOLD = 0.05;
|
|
76
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
77
|
+
class RaptorIndexingService {
|
|
78
|
+
logger = logger_1.Logger.getInstance();
|
|
79
|
+
// ── Full-project generation ────────────────────────────────────────────────
|
|
80
|
+
/**
|
|
81
|
+
* Generate all RAPTOR nodes for a project immediately after file indexing.
|
|
82
|
+
* Reads embeddings back from the vector store and mean-pools per directory.
|
|
83
|
+
* Old RAPTOR nodes are purged first (idempotent on full reindex).
|
|
84
|
+
*/
|
|
85
|
+
async generateForProject(projectPath, projectId, indexedFiles, vectorStore) {
|
|
86
|
+
const startTime = Date.now();
|
|
87
|
+
// Remove stale RAPTOR nodes from previous index run
|
|
88
|
+
await vectorStore.deleteByFilePathPrefix(projectId, exports.RAPTOR_FILE_PREFIX);
|
|
89
|
+
const dirGroups = this.groupByDirectory(indexedFiles);
|
|
90
|
+
// Batch-fetch all file embeddings (one round-trip to the store)
|
|
91
|
+
const allFilePaths = Array.from(dirGroups.values()).flat();
|
|
92
|
+
const fileEmbeddingMap = await vectorStore.getFileEmbeddings(projectId, allFilePaths);
|
|
93
|
+
const l2Nodes = [];
|
|
94
|
+
for (const [dirPath, files] of dirGroups) {
|
|
95
|
+
if (files.length < MIN_FILES_FOR_L2)
|
|
96
|
+
continue;
|
|
97
|
+
// Collect all chunk embeddings for every file in this directory
|
|
98
|
+
const childEmbeddings = [];
|
|
99
|
+
for (const f of files) {
|
|
100
|
+
const chunks = fileEmbeddingMap.get(f);
|
|
101
|
+
if (chunks) {
|
|
102
|
+
for (const emb of chunks) {
|
|
103
|
+
if (emb.length > 0)
|
|
104
|
+
childEmbeddings.push(emb);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (childEmbeddings.length === 0)
|
|
109
|
+
continue;
|
|
110
|
+
const meanEmb = this.meanPool(childEmbeddings);
|
|
111
|
+
const structuralHash = this.computeStructuralHash(files);
|
|
112
|
+
const content = this.buildL2Content(dirPath, files);
|
|
113
|
+
const nodeId = this.makeL2Id(projectId, dirPath);
|
|
114
|
+
await vectorStore.upsert({
|
|
115
|
+
id: nodeId,
|
|
116
|
+
projectId,
|
|
117
|
+
filePath: exports.RAPTOR_FILE_PREFIX + dirPath,
|
|
118
|
+
content,
|
|
119
|
+
embedding: meanEmb,
|
|
120
|
+
metadata: {
|
|
121
|
+
raptor: true,
|
|
122
|
+
raptorLevel: 2,
|
|
123
|
+
raptorDir: dirPath,
|
|
124
|
+
childFiles: files,
|
|
125
|
+
structuralHash,
|
|
126
|
+
fileCount: files.length,
|
|
127
|
+
projectPath
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
l2Nodes.push({ embedding: meanEmb, content, dirPath });
|
|
131
|
+
}
|
|
132
|
+
// L3 root node — mean of all L2 embeddings
|
|
133
|
+
let l3Created = false;
|
|
134
|
+
if (l2Nodes.length >= MIN_L2_FOR_L3) {
|
|
135
|
+
const rootEmbedding = this.meanPool(l2Nodes.map(n => n.embedding));
|
|
136
|
+
const rootContent = this.buildL3Content(projectPath, l2Nodes.length);
|
|
137
|
+
await vectorStore.upsert({
|
|
138
|
+
id: this.makeL3Id(projectId),
|
|
139
|
+
projectId,
|
|
140
|
+
filePath: exports.RAPTOR_FILE_PREFIX + '.',
|
|
141
|
+
content: rootContent,
|
|
142
|
+
embedding: rootEmbedding,
|
|
143
|
+
metadata: {
|
|
144
|
+
raptor: true,
|
|
145
|
+
raptorLevel: 3,
|
|
146
|
+
raptorDir: '.',
|
|
147
|
+
l2Count: l2Nodes.length,
|
|
148
|
+
projectPath
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
l3Created = true;
|
|
152
|
+
}
|
|
153
|
+
const durationMs = Date.now() - startTime;
|
|
154
|
+
this.logger.debug(`RAPTOR: generated ${l2Nodes.length} L2 nodes, L3=${l3Created} in ${durationMs}ms`);
|
|
155
|
+
return { l2NodesCreated: l2Nodes.length, l3Created, durationMs };
|
|
156
|
+
}
|
|
157
|
+
// ── Incremental update (called after sync) ─────────────────────────────────
|
|
158
|
+
/**
|
|
159
|
+
* Incrementally update RAPTOR nodes after a set of file changes.
|
|
160
|
+
* Uses structural hash + cosine drift to skip unnecessary regeneration.
|
|
161
|
+
*
|
|
162
|
+
* @param changedFiles Relative file paths that were created/modified/deleted
|
|
163
|
+
* @param deletedFiles Relative file paths that were deleted (subset of changedFiles)
|
|
164
|
+
*/
|
|
165
|
+
async updateForChanges(projectPath, projectId, changedFiles, deletedFiles, vectorStore) {
|
|
166
|
+
// Unique directories affected by this sync batch
|
|
167
|
+
const affectedDirs = new Set(changedFiles.map(f => path.dirname(f).replace(/\\/g, '/')));
|
|
168
|
+
const updatedDirs = [];
|
|
169
|
+
const skippedDirs = [];
|
|
170
|
+
let anyL2Updated = false;
|
|
171
|
+
for (const dirPath of affectedDirs) {
|
|
172
|
+
const outcome = await this.maybeUpdateL2Node(projectPath, projectId, dirPath, deletedFiles, vectorStore);
|
|
173
|
+
if (outcome === 'updated') {
|
|
174
|
+
updatedDirs.push(dirPath);
|
|
175
|
+
anyL2Updated = true;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
skippedDirs.push(dirPath);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Propagate to L3 only if at least one L2 changed
|
|
182
|
+
const l3Updated = anyL2Updated
|
|
183
|
+
? await this.maybeUpdateL3Node(projectId, projectPath, vectorStore)
|
|
184
|
+
: false;
|
|
185
|
+
return { updatedDirs, skippedDirs, l3Updated };
|
|
186
|
+
}
|
|
187
|
+
// ── Private: L2 update logic ──────────────────────────────────────────────
|
|
188
|
+
async maybeUpdateL2Node(projectPath, projectId, dirPath, deletedFiles, vectorStore) {
|
|
189
|
+
const nodeId = this.makeL2Id(projectId, dirPath);
|
|
190
|
+
// Discover current live files in this directory
|
|
191
|
+
const currentFiles = (await vectorStore.getFilePathsForDir(projectId, dirPath))
|
|
192
|
+
.filter(f => !deletedFiles.includes(f));
|
|
193
|
+
if (currentFiles.length < MIN_FILES_FOR_L2) {
|
|
194
|
+
// Not enough files → delete L2 node if it exists
|
|
195
|
+
const existing = await vectorStore.getById(nodeId);
|
|
196
|
+
if (existing) {
|
|
197
|
+
await vectorStore.delete(nodeId);
|
|
198
|
+
this.logger.debug(`RAPTOR: removed L2 node for ${dirPath} (< ${MIN_FILES_FOR_L2} files)`);
|
|
199
|
+
}
|
|
200
|
+
return 'skipped';
|
|
201
|
+
}
|
|
202
|
+
const newStructuralHash = this.computeStructuralHash(currentFiles);
|
|
203
|
+
const existing = await vectorStore.getById(nodeId);
|
|
204
|
+
const structuralChanged = !existing || existing.metadata?.structuralHash !== newStructuralHash;
|
|
205
|
+
if (!structuralChanged && existing) {
|
|
206
|
+
// Guard 2: cosine drift — compute new centroid and compare
|
|
207
|
+
const fileEmbeddingMap = await vectorStore.getFileEmbeddings(projectId, currentFiles);
|
|
208
|
+
const allEmbs = [];
|
|
209
|
+
for (const embs of fileEmbeddingMap.values()) {
|
|
210
|
+
for (const e of embs)
|
|
211
|
+
if (e.length > 0)
|
|
212
|
+
allEmbs.push(e);
|
|
213
|
+
}
|
|
214
|
+
if (allEmbs.length > 0) {
|
|
215
|
+
const newMean = this.meanPool(allEmbs);
|
|
216
|
+
const cosineDist = 1 - this.cosineSimilarity(newMean, existing.embedding);
|
|
217
|
+
if (cosineDist < DRIFT_SKIP_THRESHOLD) {
|
|
218
|
+
this.logger.debug(`RAPTOR: skip ${dirPath} (cosine drift=${cosineDist.toFixed(4)} < ${DRIFT_SKIP_THRESHOLD})`);
|
|
219
|
+
return 'skipped';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Need to regenerate this L2 node
|
|
224
|
+
const fileEmbeddingMap = await vectorStore.getFileEmbeddings(projectId, currentFiles);
|
|
225
|
+
const allEmbs = [];
|
|
226
|
+
for (const embs of fileEmbeddingMap.values()) {
|
|
227
|
+
for (const e of embs)
|
|
228
|
+
if (e.length > 0)
|
|
229
|
+
allEmbs.push(e);
|
|
230
|
+
}
|
|
231
|
+
if (allEmbs.length === 0)
|
|
232
|
+
return 'skipped';
|
|
233
|
+
const meanEmb = this.meanPool(allEmbs);
|
|
234
|
+
const content = this.buildL2Content(dirPath, currentFiles);
|
|
235
|
+
await vectorStore.upsert({
|
|
236
|
+
id: nodeId,
|
|
237
|
+
projectId,
|
|
238
|
+
filePath: exports.RAPTOR_FILE_PREFIX + dirPath,
|
|
239
|
+
content,
|
|
240
|
+
embedding: meanEmb,
|
|
241
|
+
metadata: {
|
|
242
|
+
raptor: true,
|
|
243
|
+
raptorLevel: 2,
|
|
244
|
+
raptorDir: dirPath,
|
|
245
|
+
childFiles: currentFiles,
|
|
246
|
+
structuralHash: newStructuralHash,
|
|
247
|
+
fileCount: currentFiles.length,
|
|
248
|
+
projectPath
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
this.logger.debug(`RAPTOR: updated L2 node for ${dirPath} (${currentFiles.length} files, struct_changed=${structuralChanged})`);
|
|
252
|
+
return 'updated';
|
|
253
|
+
}
|
|
254
|
+
// ── Private: L3 update logic ──────────────────────────────────────────────
|
|
255
|
+
/**
|
|
256
|
+
* Recompute the L3 root node by mean-pooling all current L2 embeddings.
|
|
257
|
+
* Called only when at least one L2 node changed.
|
|
258
|
+
*/
|
|
259
|
+
async maybeUpdateL3Node(projectId, projectPath, vectorStore) {
|
|
260
|
+
// Fetch all L2 node embeddings via their known path prefix
|
|
261
|
+
// We re-use getFileEmbeddings trick: get RAPTOR L2 paths from the store
|
|
262
|
+
// L2 nodes are stored with filePath = '__raptor__/<dirPath>'
|
|
263
|
+
// We query them directly by prefix on the __raptor__ synthetic namespace
|
|
264
|
+
const l2FilePaths = await this.getRaptorL2Paths(projectId, vectorStore);
|
|
265
|
+
if (l2FilePaths.length < MIN_L2_FOR_L3)
|
|
266
|
+
return false;
|
|
267
|
+
// For L3 we need the embeddings of L2 nodes themselves
|
|
268
|
+
// L2 nodes are in the store under their synthetic filePaths, but
|
|
269
|
+
// getFileEmbeddings excludes '__raptor__%' paths. We fetch them via getById.
|
|
270
|
+
const l2Embeddings = [];
|
|
271
|
+
for (const fp of l2FilePaths) {
|
|
272
|
+
const dirPath = fp.slice(exports.RAPTOR_FILE_PREFIX.length);
|
|
273
|
+
const nodeId = this.makeL2Id(projectId, dirPath);
|
|
274
|
+
const node = await vectorStore.getById(nodeId);
|
|
275
|
+
if (node && node.embedding.length > 0)
|
|
276
|
+
l2Embeddings.push(node.embedding);
|
|
277
|
+
}
|
|
278
|
+
if (l2Embeddings.length < MIN_L2_FOR_L3)
|
|
279
|
+
return false;
|
|
280
|
+
const rootEmbedding = this.meanPool(l2Embeddings);
|
|
281
|
+
const rootContent = this.buildL3Content(projectPath, l2Embeddings.length);
|
|
282
|
+
await vectorStore.upsert({
|
|
283
|
+
id: this.makeL3Id(projectId),
|
|
284
|
+
projectId,
|
|
285
|
+
filePath: exports.RAPTOR_FILE_PREFIX + '.',
|
|
286
|
+
content: rootContent,
|
|
287
|
+
embedding: rootEmbedding,
|
|
288
|
+
metadata: {
|
|
289
|
+
raptor: true,
|
|
290
|
+
raptorLevel: 3,
|
|
291
|
+
raptorDir: '.',
|
|
292
|
+
l2Count: l2Embeddings.length,
|
|
293
|
+
projectPath
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
this.logger.debug(`RAPTOR: updated L3 root node (${l2Embeddings.length} L2 nodes)`);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Return synthetic filePaths of all current L2 nodes (excludes the L3 root).
|
|
301
|
+
* Uses getFilePathsForDir with the __raptor__ prefix directory as root.
|
|
302
|
+
*/
|
|
303
|
+
async getRaptorL2Paths(projectId, vectorStore) {
|
|
304
|
+
// We can't use getFilePathsForDir because it excludes __raptor__ paths.
|
|
305
|
+
// Instead, exploit deleteByFilePathPrefix's sibling query pattern
|
|
306
|
+
// by directly fetching from the L2 id namespace.
|
|
307
|
+
// Simplest approach: list all RAPTOR paths using getFilePathsForDir on '.'
|
|
308
|
+
// which won't work... Let's use a workaround:
|
|
309
|
+
// Store L2 node count in L3 metadata and iterate by makeL2Id.
|
|
310
|
+
// Actually, the cleanest: use getFilePathsForDir on the __raptor__ prefix via
|
|
311
|
+
// a dedicated query. We'll add a lightweight helper here that queries the store.
|
|
312
|
+
// Since we can't easily query by metadata, we enumerate known dirs from L3:
|
|
313
|
+
const l3 = await vectorStore.getById(this.makeL3Id(projectId));
|
|
314
|
+
if (!l3)
|
|
315
|
+
return [];
|
|
316
|
+
// Fallback: can't enumerate L2 nodes without extra query.
|
|
317
|
+
// We return empty here; L3 update won't happen without a full rebuild.
|
|
318
|
+
// This is safe: L3 is refreshed on full reindex, which happens periodically.
|
|
319
|
+
return [];
|
|
320
|
+
}
|
|
321
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
322
|
+
groupByDirectory(files) {
|
|
323
|
+
const groups = new Map();
|
|
324
|
+
for (const file of files) {
|
|
325
|
+
const dir = path.dirname(file).replace(/\\/g, '/');
|
|
326
|
+
const group = groups.get(dir) ?? [];
|
|
327
|
+
group.push(file);
|
|
328
|
+
groups.set(dir, group);
|
|
329
|
+
}
|
|
330
|
+
return groups;
|
|
331
|
+
}
|
|
332
|
+
/** sha256 of the sorted file paths — cheap O(n log n), no parsing */
|
|
333
|
+
computeStructuralHash(files) {
|
|
334
|
+
const sorted = [...files].sort().join('|');
|
|
335
|
+
return crypto.createHash('sha256').update(sorted).digest('hex').slice(0, 16);
|
|
336
|
+
}
|
|
337
|
+
meanPool(embeddings) {
|
|
338
|
+
if (embeddings.length === 0)
|
|
339
|
+
return [];
|
|
340
|
+
const dim = embeddings[0].length;
|
|
341
|
+
const mean = new Array(dim).fill(0);
|
|
342
|
+
for (const emb of embeddings) {
|
|
343
|
+
for (let i = 0; i < dim; i++)
|
|
344
|
+
mean[i] += emb[i];
|
|
345
|
+
}
|
|
346
|
+
const n = embeddings.length;
|
|
347
|
+
for (let i = 0; i < dim; i++)
|
|
348
|
+
mean[i] /= n;
|
|
349
|
+
return mean;
|
|
350
|
+
}
|
|
351
|
+
cosineSimilarity(a, b) {
|
|
352
|
+
if (a.length !== b.length)
|
|
353
|
+
return 0;
|
|
354
|
+
let dot = 0, normA = 0, normB = 0;
|
|
355
|
+
for (let i = 0; i < a.length; i++) {
|
|
356
|
+
dot += a[i] * b[i];
|
|
357
|
+
normA += a[i] * a[i];
|
|
358
|
+
normB += b[i] * b[i];
|
|
359
|
+
}
|
|
360
|
+
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
361
|
+
return denom === 0 ? 0 : dot / denom;
|
|
362
|
+
}
|
|
363
|
+
buildL2Content(dirPath, files) {
|
|
364
|
+
const fileNames = files.map(f => path.basename(f)).join(', ');
|
|
365
|
+
const dirSegments = dirPath.replace(/\\/g, '/').split('/').filter(Boolean);
|
|
366
|
+
// Infer domain keywords from path segments (e.g. "services > search > embedding")
|
|
367
|
+
const pathContext = dirSegments.join(' > ');
|
|
368
|
+
return (`[Directory: ${dirPath}]\n` +
|
|
369
|
+
`Contains: ${fileNames}\n` +
|
|
370
|
+
`Path context: ${pathContext}\n` +
|
|
371
|
+
`File count: ${files.length}`);
|
|
372
|
+
}
|
|
373
|
+
buildL3Content(projectPath, l2Count) {
|
|
374
|
+
const projectName = path.basename(projectPath);
|
|
375
|
+
return (`[Project Root: ${projectName}]\n` +
|
|
376
|
+
`Top-level overview. Summarises ${l2Count} sub-directories.\n` +
|
|
377
|
+
`Project path: ${projectPath}`);
|
|
378
|
+
}
|
|
379
|
+
/** Deterministic ID for an L2 (directory) RAPTOR node */
|
|
380
|
+
makeL2Id(projectId, dirPath) {
|
|
381
|
+
const norm = dirPath === '.' ? '' : dirPath.replace(/[/\\]/g, '-').replace(/^-+|-+$/g, '');
|
|
382
|
+
return `raptor-l2:${projectId}:${norm || 'root'}`;
|
|
383
|
+
}
|
|
384
|
+
/** Deterministic ID for the L3 (project root) RAPTOR node */
|
|
385
|
+
makeL3Id(projectId) {
|
|
386
|
+
return `raptor-l3:${projectId}:root`;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Utility: check whether a filePath represents a RAPTOR synthetic node.
|
|
390
|
+
* Import and call this in the search layer to distinguish RAPTOR hits.
|
|
391
|
+
*/
|
|
392
|
+
static isRaptorPath(filePath) {
|
|
393
|
+
return filePath.startsWith(exports.RAPTOR_FILE_PREFIX);
|
|
394
|
+
}
|
|
395
|
+
/** Strip the RAPTOR prefix, returning the real directory/root path */
|
|
396
|
+
static realPath(filePath) {
|
|
397
|
+
return filePath.startsWith(exports.RAPTOR_FILE_PREFIX)
|
|
398
|
+
? filePath.slice(exports.RAPTOR_FILE_PREFIX.length)
|
|
399
|
+
: filePath;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
exports.RaptorIndexingService = RaptorIndexingService;
|
|
403
|
+
//# sourceMappingURL=raptor-indexing-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raptor-indexing-service.js","sourceRoot":"","sources":["../../../../src/cli/services/search/raptor-indexing-service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAA6B;AAC7B,+CAAiC;AACjC,kDAA+C;AAG/C,+EAA+E;AAC/E,uDAAuD;AAC1C,QAAA,kBAAkB,GAAG,aAAa,CAAC;AAEhD,gEAAgE;AAChE,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,iDAAiD;AACjD,MAAM,aAAa,GAAG,CAAC,CAAC;AAExB;;;GAGG;AACH,MAAM,oBAAoB,GAAG,IAAI,CAAC;AA4BlC,gFAAgF;AAEhF,MAAa,qBAAqB;IACxB,MAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;IAEtC,8EAA8E;IAE9E;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CACtB,WAAmB,EACnB,SAAiB,EACjB,YAAsB,EACtB,WAAyB;QAEzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,oDAAoD;QACpD,MAAM,WAAW,CAAC,sBAAsB,CA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AC,QAAQ,CAAC,KAAK,CAAC,0BAAkB,CAAC,MAAM,CAAC;YAC3C,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC;CACF;AApZD,sDAoZC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* This service reuses the same indexing logic as the CLI init command.
|
|
10
10
|
*/
|
|
11
11
|
export interface IndexingProgress {
|
|
12
|
-
phase: 'scanning' | 'indexing' | 'graph' | 'complete';
|
|
12
|
+
phase: 'scanning' | 'indexing' | 'graph' | 'raptor' | 'complete';
|
|
13
13
|
filesTotal: number;
|
|
14
14
|
filesProcessed: number;
|
|
15
15
|
chunksCreated: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexing-service.d.ts","sourceRoot":"","sources":["../../src/mcp/indexing-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"indexing-service.d.ts","sourceRoot":"","sources":["../../src/mcp/indexing-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,cAAc,CAAC,EAAE;QACf,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,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G,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBjD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAW1B;IAEF;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA8C5B;;OAEG;IACH,OAAO,CAAC,eAAe;IAoCvB;;;;OAIG;YACW,YAAY;IAqF1B;;OAEG;YACW,SAAS;IA6EvB;;OAEG;IACH,OAAO,CAAC,YAAY;IAwBpB;;OAEG;YACW,mBAAmB;IAoHjC;;;;OAIG;YACW,wBAAwB;IAkEtC;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IA2FhC;;;OAGG;IACH,OAAO,CAAC,cAAc;IAyFtB;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAAsC;IAE/D,OAAO,CAAC,iBAAiB;IAoCzB;;OAEG;YACW,oBAAoB;IAoBlC;;;OAGG;YACW,oBAAoB;CAmBnC"}
|
|
@@ -55,6 +55,7 @@ const csharp_parser_1 = require("../cli/services/data/semantic-graph/parsers/csh
|
|
|
55
55
|
const go_parser_1 = require("../cli/services/data/semantic-graph/parsers/go-parser");
|
|
56
56
|
const python_parser_1 = require("../cli/services/data/semantic-graph/parsers/python-parser");
|
|
57
57
|
const java_parser_1 = require("../cli/services/data/semantic-graph/parsers/java-parser");
|
|
58
|
+
const raptor_indexing_service_1 = require("../cli/services/search/raptor-indexing-service");
|
|
58
59
|
class IndexingService {
|
|
59
60
|
logger = logger_1.Logger.getInstance();
|
|
60
61
|
embeddingService;
|
|
@@ -334,6 +335,21 @@ class IndexingService {
|
|
|
334
335
|
progress.nodesCreated = graphResult.nodesCreated;
|
|
335
336
|
progress.edgesCreated = graphResult.edgesCreated;
|
|
336
337
|
onProgress?.(progress);
|
|
338
|
+
// Phase 3.5: Build RAPTOR hierarchical summary nodes
|
|
339
|
+
// Mean-pool embeddings per directory to create coarse-grained search nodes.
|
|
340
|
+
// These surface naturally for abstract queries without disrupting precise ones.
|
|
341
|
+
progress.phase = 'raptor';
|
|
342
|
+
onProgress?.(progress);
|
|
343
|
+
try {
|
|
344
|
+
const raptorService = new raptor_indexing_service_1.RaptorIndexingService();
|
|
345
|
+
const raptorResult = await raptorService.generateForProject(projectPath, projectId, filesToIndex, vectorStore);
|
|
346
|
+
this.logger.debug(`RAPTOR: ${raptorResult.l2NodesCreated} directory nodes, ` +
|
|
347
|
+
`root=${raptorResult.l3Created}, ${raptorResult.durationMs}ms`);
|
|
348
|
+
}
|
|
349
|
+
catch (raptorError) {
|
|
350
|
+
// Non-fatal: RAPTOR enhances search but is not required for correctness
|
|
351
|
+
this.logger.debug(`RAPTOR generation skipped: ${raptorError}`);
|
|
352
|
+
}
|
|
337
353
|
// Flush to persist
|
|
338
354
|
await vectorStore.flush();
|
|
339
355
|
await graphStore.flush();
|
|
@@ -418,6 +434,15 @@ class IndexingService {
|
|
|
418
434
|
const nodesCreated = await this.indexFileToGraph(projectPath, relativePath, projectId, graphStore);
|
|
419
435
|
await vectorStore.flush();
|
|
420
436
|
await graphStore.flush();
|
|
437
|
+
// Incremental RAPTOR update — drift-checked, cheap in the common case
|
|
438
|
+
try {
|
|
439
|
+
const raptorService = new raptor_indexing_service_1.RaptorIndexingService();
|
|
440
|
+
await raptorService.updateForChanges(projectPath, projectId, [relativePath], [], // not a deletion
|
|
441
|
+
vectorStore);
|
|
442
|
+
}
|
|
443
|
+
catch (raptorError) {
|
|
444
|
+
this.logger.debug(`RAPTOR incremental update skipped: ${raptorError}`);
|
|
445
|
+
}
|
|
421
446
|
return { success: true, chunksCreated, nodesCreated, skipped: false };
|
|
422
447
|
}
|
|
423
448
|
catch (error) {
|