neuralbrain 0.0.1 → 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/.env.example +2 -2
- package/README.md +19 -4
- package/dist/ai/chat.d.ts +1 -2
- package/dist/ai/chat.d.ts.map +1 -1
- package/dist/ai/chat.js +1 -2
- package/dist/ai/chat.js.map +1 -1
- package/dist/ai/config.d.ts +1 -1
- package/dist/ai/config.js +2 -2
- package/dist/ai/config.js.map +1 -1
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +417 -50
- package/dist/app.js.map +1 -1
- package/dist/cli.d.ts +53 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +437 -37
- package/dist/cli.js.map +1 -1
- package/dist/consolidation/candidates.d.ts.map +1 -1
- package/dist/consolidation/candidates.js +19 -4
- package/dist/consolidation/candidates.js.map +1 -1
- package/dist/consolidation/fixtures.js +1 -1
- package/dist/consolidation/fixtures.js.map +1 -1
- package/dist/consolidation/gate.d.ts.map +1 -1
- package/dist/consolidation/gate.js +145 -109
- package/dist/consolidation/gate.js.map +1 -1
- package/dist/consolidation/runner.d.ts +6 -0
- package/dist/consolidation/runner.d.ts.map +1 -1
- package/dist/consolidation/runner.js +22 -2
- package/dist/consolidation/runner.js.map +1 -1
- package/dist/dashboard/clientScript.d.ts +1 -1
- package/dist/dashboard/clientScript.d.ts.map +1 -1
- package/dist/dashboard/clientScript.js +3774 -905
- package/dist/dashboard/clientScript.js.map +1 -1
- package/dist/dashboard/html.d.ts.map +1 -1
- package/dist/dashboard/html.js +605 -101
- package/dist/dashboard/html.js.map +1 -1
- package/dist/dashboard/styles.d.ts +1 -1
- package/dist/dashboard/styles.d.ts.map +1 -1
- package/dist/dashboard/styles.js +1591 -359
- package/dist/dashboard/styles.js.map +1 -1
- package/dist/learning/embedWorker.d.ts +13 -0
- package/dist/learning/embedWorker.d.ts.map +1 -1
- package/dist/learning/embedWorker.js +329 -59
- package/dist/learning/embedWorker.js.map +1 -1
- package/dist/learning/embedding.d.ts +1 -0
- package/dist/learning/embedding.d.ts.map +1 -1
- package/dist/learning/embedding.js +101 -26
- package/dist/learning/embedding.js.map +1 -1
- package/dist/learning/engine.js +1 -1
- package/dist/learning/engine.js.map +1 -1
- package/dist/learning/search.d.ts +17 -1
- package/dist/learning/search.d.ts.map +1 -1
- package/dist/learning/search.js +2094 -354
- package/dist/learning/search.js.map +1 -1
- package/dist/learning/storeMeta.d.ts +9 -0
- package/dist/learning/storeMeta.d.ts.map +1 -1
- package/dist/learning/storeMeta.js +30 -24
- package/dist/learning/storeMeta.js.map +1 -1
- package/dist/learning/types.d.ts +57 -8
- package/dist/learning/types.d.ts.map +1 -1
- package/dist/lib/condenser.d.ts +112 -0
- package/dist/lib/condenser.d.ts.map +1 -0
- package/dist/lib/condenser.js +1337 -0
- package/dist/lib/condenser.js.map +1 -0
- package/dist/lib/db.d.ts +10 -0
- package/dist/lib/db.d.ts.map +1 -1
- package/dist/lib/db.js +654 -167
- package/dist/lib/db.js.map +1 -1
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +3 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/projectSlug.d.ts +12 -5
- package/dist/lib/projectSlug.d.ts.map +1 -1
- package/dist/lib/projectSlug.js +62 -23
- package/dist/lib/projectSlug.js.map +1 -1
- package/dist/lib/recurrence.d.ts +16 -0
- package/dist/lib/recurrence.d.ts.map +1 -0
- package/dist/lib/recurrence.js +293 -0
- package/dist/lib/recurrence.js.map +1 -0
- package/dist/lib/scope.d.ts +36 -1
- package/dist/lib/scope.d.ts.map +1 -1
- package/dist/lib/scope.js +183 -19
- package/dist/lib/scope.js.map +1 -1
- package/dist/lib/signalTags.d.ts +39 -0
- package/dist/lib/signalTags.d.ts.map +1 -0
- package/dist/lib/signalTags.js +203 -0
- package/dist/lib/signalTags.js.map +1 -0
- package/dist/lib/spool.d.ts +2 -0
- package/dist/lib/spool.d.ts.map +1 -1
- package/dist/lib/spool.js +176 -65
- package/dist/lib/spool.js.map +1 -1
- package/dist/lib/storeDiagnostics.d.ts +41 -0
- package/dist/lib/storeDiagnostics.d.ts.map +1 -0
- package/dist/lib/storeDiagnostics.js +148 -0
- package/dist/lib/storeDiagnostics.js.map +1 -0
- package/dist/lib/temporal.d.ts +44 -0
- package/dist/lib/temporal.d.ts.map +1 -0
- package/dist/lib/temporal.js +1063 -0
- package/dist/lib/temporal.js.map +1 -0
- package/dist/mcp/server.d.ts +93 -3
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +499 -68
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/actionStore.d.ts +94 -3
- package/dist/memory/actionStore.d.ts.map +1 -1
- package/dist/memory/actionStore.js +412 -124
- package/dist/memory/actionStore.js.map +1 -1
- package/dist/memory/deadLetterStore.d.ts.map +1 -1
- package/dist/memory/deadLetterStore.js +4 -2
- package/dist/memory/deadLetterStore.js.map +1 -1
- package/dist/memory/embedQueueStore.d.ts +19 -8
- package/dist/memory/embedQueueStore.d.ts.map +1 -1
- package/dist/memory/embedQueueStore.js +55 -25
- package/dist/memory/embedQueueStore.js.map +1 -1
- package/dist/memory/failurePatternStore.d.ts +17 -1
- package/dist/memory/failurePatternStore.d.ts.map +1 -1
- package/dist/memory/failurePatternStore.js +54 -31
- package/dist/memory/failurePatternStore.js.map +1 -1
- package/dist/memory/graphStore.d.ts +133 -3
- package/dist/memory/graphStore.d.ts.map +1 -1
- package/dist/memory/graphStore.js +980 -155
- package/dist/memory/graphStore.js.map +1 -1
- package/dist/memory/noteStore.d.ts +27 -2
- package/dist/memory/noteStore.d.ts.map +1 -1
- package/dist/memory/noteStore.js +89 -26
- package/dist/memory/noteStore.js.map +1 -1
- package/dist/memory/observationStore.d.ts +11 -1
- package/dist/memory/observationStore.d.ts.map +1 -1
- package/dist/memory/observationStore.js +90 -15
- package/dist/memory/observationStore.js.map +1 -1
- package/dist/memory/projectRename.d.ts.map +1 -1
- package/dist/memory/projectRename.js +5 -1
- package/dist/memory/projectRename.js.map +1 -1
- package/dist/memory/rollupSweeper.d.ts.map +1 -1
- package/dist/memory/rollupSweeper.js +43 -23
- package/dist/memory/rollupSweeper.js.map +1 -1
- package/dist/memory/sessionStore.d.ts +25 -7
- package/dist/memory/sessionStore.d.ts.map +1 -1
- package/dist/memory/sessionStore.js +145 -33
- package/dist/memory/sessionStore.js.map +1 -1
- package/dist/memory/trajectoryStore.d.ts +8 -0
- package/dist/memory/trajectoryStore.d.ts.map +1 -1
- package/dist/memory/trajectoryStore.js +196 -130
- package/dist/memory/trajectoryStore.js.map +1 -1
- package/dist/middleware/rateLimiter.d.ts.map +1 -1
- package/dist/middleware/rateLimiter.js +24 -1
- package/dist/middleware/rateLimiter.js.map +1 -1
- package/dist/routes/dashboard.d.ts.map +1 -1
- package/dist/routes/dashboard.js +181 -8
- package/dist/routes/dashboard.js.map +1 -1
- package/dist/routes/mcp.d.ts.map +1 -1
- package/dist/routes/mcp.js +173 -21
- package/dist/routes/mcp.js.map +1 -1
- package/dist/routes/memories.js +9 -1
- package/dist/routes/memories.js.map +1 -1
- package/dist/scripts/doctor.d.ts +26 -2
- package/dist/scripts/doctor.d.ts.map +1 -1
- package/dist/scripts/doctor.js +371 -259
- package/dist/scripts/doctor.js.map +1 -1
- package/dist/scripts/installAgent.d.ts.map +1 -1
- package/dist/scripts/installAgent.js +101 -19
- package/dist/scripts/installAgent.js.map +1 -1
- package/dist/scripts/migrateAgentMemory.js +2 -2
- package/dist/scripts/smokeTest.js +1 -1
- package/dist/scripts/smokeTest.js.map +1 -1
- package/docker-compose.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +3 -2
- package/plugin/hooks/postToolUse.js +155 -50
- package/plugin/hooks/sessionStart.js +179 -27
- package/plugin/hooks/sessionStop.js +152 -37
- package/plugin/plugin.json +1 -1
- package/plugin/rules/AGENTS.md +10 -8
- package/plugin/skills/brain-memory/REFERENCE.md +15 -14
- package/plugin/skills/brain-memory/SKILL.md +2 -2
- package/plugin/skills/digest/SKILL.md +1 -1
- package/plugin/skills/handoff/SKILL.md +1 -1
- package/plugin/skills/save/SKILL.md +2 -2
- package/plugin/skills/search/SKILL.md +2 -2
- package/src/ai/chat.ts +1 -2
- package/src/ai/config.ts +2 -2
- package/src/app.ts +475 -54
- package/src/cli.ts +500 -38
- package/src/consolidation/candidates.ts +22 -4
- package/src/consolidation/fixtures.ts +1 -1
- package/src/consolidation/gate.ts +177 -140
- package/src/consolidation/runner.ts +26 -2
- package/src/dashboard/clientScript.ts +3774 -905
- package/src/dashboard/html.ts +605 -101
- package/src/dashboard/styles.ts +1591 -359
- package/src/learning/embedWorker.ts +350 -70
- package/src/learning/embedding.ts +141 -28
- package/src/learning/engine.ts +1 -1
- package/src/learning/search.ts +2533 -397
- package/src/learning/storeMeta.ts +36 -29
- package/src/learning/types.ts +66 -8
- package/src/lib/condenser.ts +1515 -0
- package/src/lib/db.ts +690 -171
- package/src/lib/logger.ts +4 -2
- package/src/lib/projectSlug.ts +77 -23
- package/src/lib/recurrence.ts +382 -0
- package/src/lib/scope.ts +220 -22
- package/src/lib/signalTags.ts +257 -0
- package/src/lib/spool.ts +181 -71
- package/src/lib/storeDiagnostics.ts +181 -0
- package/src/lib/temporal.ts +1250 -0
- package/src/mcp/server.ts +559 -88
- package/src/memory/actionStore.ts +642 -171
- package/src/memory/deadLetterStore.ts +4 -2
- package/src/memory/embedQueueStore.ts +63 -27
- package/src/memory/failurePatternStore.ts +84 -31
- package/src/memory/graphStore.ts +1396 -215
- package/src/memory/noteStore.ts +151 -30
- package/src/memory/observationStore.ts +117 -17
- package/src/memory/projectRename.ts +6 -2
- package/src/memory/rollupSweeper.ts +46 -23
- package/src/memory/sessionStore.ts +197 -38
- package/src/memory/trajectoryStore.ts +260 -140
- package/src/middleware/rateLimiter.ts +24 -1
- package/src/routes/dashboard.ts +194 -9
- package/src/routes/mcp.ts +185 -26
- package/src/routes/memories.ts +8 -1
- package/src/scripts/doctor.ts +461 -262
- package/src/scripts/installAgent.ts +106 -19
- package/src/scripts/migrateAgentMemory.ts +2 -2
- package/src/scripts/smokeTest.ts +1 -1
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
2
|
+
import crypto from 'crypto';
|
|
2
3
|
import { getDb } from '../lib/db';
|
|
3
4
|
import { logger } from '../lib/logger';
|
|
5
|
+
import { getProjectAncestors } from '../lib/scope';
|
|
4
6
|
import {
|
|
5
7
|
claimEmbedQueue,
|
|
8
|
+
clearEmbedQueueTarget,
|
|
6
9
|
enqueueForEmbedding,
|
|
7
10
|
getPendingEmbedCount,
|
|
8
11
|
markEmbedDone,
|
|
9
12
|
markEmbedFailed,
|
|
13
|
+
recoverStaleRunningEmbeds,
|
|
10
14
|
releaseEmbedClaim,
|
|
11
|
-
type
|
|
15
|
+
type EmbedRecordType,
|
|
12
16
|
} from '../memory/embedQueueStore';
|
|
13
17
|
import {
|
|
14
18
|
EmbeddingConfigurationError,
|
|
15
19
|
buildTrajectoryEmbeddingText,
|
|
16
20
|
embedDocument,
|
|
21
|
+
embedDocuments,
|
|
17
22
|
resolveEmbedderRecipe,
|
|
18
23
|
serializeEmbedding,
|
|
19
24
|
} from './embedding';
|
|
@@ -25,6 +30,8 @@ export interface DrainOptions {
|
|
|
25
30
|
batchSize?: number;
|
|
26
31
|
maxBatches?: number;
|
|
27
32
|
client?: QdrantClient;
|
|
33
|
+
skipSqliteBlobUpdate?: boolean;
|
|
34
|
+
onVectorsComputed?: (vectors: Array<{ id: string; record_type: EmbedRecordType; blob: Buffer }>) => void;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export interface ReembedStatus {
|
|
@@ -88,6 +95,19 @@ export function getQdrantClient(): QdrantClient | null {
|
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
|
|
98
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Qdrant only accepts unsigned integers or UUIDs as point IDs.
|
|
102
|
+
* Map non-UUID record IDs (e.g. note_*, obs_*, sum_*) deterministically to a UUID
|
|
103
|
+
* while storing the original record_id in the point payload.
|
|
104
|
+
*/
|
|
105
|
+
export function toQdrantPointId(recordId: string): string {
|
|
106
|
+
if (UUID_RE.test(recordId)) return recordId;
|
|
107
|
+
const hex = crypto.createHash('sha256').update(recordId).digest('hex').slice(0, 32);
|
|
108
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
91
111
|
/**
|
|
92
112
|
* Safely delete points from Qdrant by id.
|
|
93
113
|
* Never throws — logs warnings on error or skips if Qdrant is unreachable / embedder tier is none.
|
|
@@ -106,7 +126,7 @@ export async function deleteQdrantPoints(
|
|
|
106
126
|
|
|
107
127
|
const collection = getStoreMeta()?.qdrant_alias || 'brain';
|
|
108
128
|
await qdrant.delete(collection, {
|
|
109
|
-
points: ids,
|
|
129
|
+
points: ids.map(toQdrantPointId),
|
|
110
130
|
});
|
|
111
131
|
logger.debug({ count: ids.length, collection }, 'deleted points from qdrant');
|
|
112
132
|
} catch (err) {
|
|
@@ -120,6 +140,33 @@ export async function deleteQdrantPoints(
|
|
|
120
140
|
}
|
|
121
141
|
}
|
|
122
142
|
|
|
143
|
+
const EMBEDDING_TABLE_BY_TYPE: Partial<Record<EmbedRecordType, string>> = {
|
|
144
|
+
trajectory: 'trajectories',
|
|
145
|
+
note: 'notes',
|
|
146
|
+
summary: 'summaries',
|
|
147
|
+
entity: 'entities',
|
|
148
|
+
action: 'actions',
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
function toUnixSeconds(raw: unknown): number {
|
|
152
|
+
if (typeof raw === 'number' && Number.isFinite(raw)) {
|
|
153
|
+
return Math.floor(raw);
|
|
154
|
+
}
|
|
155
|
+
if (typeof raw === 'string') {
|
|
156
|
+
const trimmed = raw.trim();
|
|
157
|
+
if (trimmed) {
|
|
158
|
+
const iso = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(trimmed)
|
|
159
|
+
? `${trimmed.replace(' ', 'T')}Z`
|
|
160
|
+
: trimmed;
|
|
161
|
+
const ms = Date.parse(iso);
|
|
162
|
+
if (Number.isFinite(ms)) {
|
|
163
|
+
return Math.floor(ms / 1000);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return Math.floor(Date.now() / 1000);
|
|
168
|
+
}
|
|
169
|
+
|
|
123
170
|
let isDrainRunning = false;
|
|
124
171
|
|
|
125
172
|
export async function drainEmbedQueue(
|
|
@@ -145,6 +192,10 @@ export async function drainEmbedQueue(
|
|
|
145
192
|
const batchSize = options?.batchSize || 32;
|
|
146
193
|
const maxBatches = options?.maxBatches || 1;
|
|
147
194
|
const qdrant = options?.client ?? getQdrantClient();
|
|
195
|
+
const qdrantConfigured = Boolean(options?.client || process.env.QDRANT_URL?.trim());
|
|
196
|
+
const skipSqliteBlobUpdate = options?.skipSqliteBlobUpdate ?? target !== 'live';
|
|
197
|
+
|
|
198
|
+
recoverStaleRunningEmbeds(target);
|
|
148
199
|
|
|
149
200
|
const recipe = resolveEmbedderRecipe();
|
|
150
201
|
const db = getDb();
|
|
@@ -161,6 +212,13 @@ export async function drainEmbedQueue(
|
|
|
161
212
|
}
|
|
162
213
|
|
|
163
214
|
const qdrantPointsToUpsert: Array<{ id: string; vector: number[]; payload: Record<string, any> }> = [];
|
|
215
|
+
const pendingQdrantDone: Array<{ record_id: string; record_type: EmbedRecordType }> = [];
|
|
216
|
+
const computedBlobs: Array<{ id: string; record_type: EmbedRecordType; blob: Buffer }> = [];
|
|
217
|
+
const preparedItems: Array<{
|
|
218
|
+
item: (typeof items)[number];
|
|
219
|
+
text: string;
|
|
220
|
+
payload: Record<string, any>;
|
|
221
|
+
}> = [];
|
|
164
222
|
|
|
165
223
|
for (let itemIdx = 0; itemIdx < items.length; itemIdx++) {
|
|
166
224
|
const item = items[itemIdx];
|
|
@@ -168,27 +226,29 @@ export async function drainEmbedQueue(
|
|
|
168
226
|
let text = '';
|
|
169
227
|
let payload: Record<string, any> = {};
|
|
170
228
|
|
|
171
|
-
switch (item.
|
|
229
|
+
switch (item.record_type) {
|
|
172
230
|
case 'observation': {
|
|
173
231
|
const obs = db
|
|
174
232
|
.prepare('SELECT * FROM observations WHERE id = ?')
|
|
175
233
|
.get(item.record_id) as any;
|
|
176
234
|
if (!obs) {
|
|
177
|
-
markEmbedDone(item.record_id, item.
|
|
235
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
178
236
|
totalProcessed++;
|
|
179
237
|
continue;
|
|
180
238
|
}
|
|
181
239
|
text = [
|
|
182
|
-
obs.kind === 'prompt' ? 'prompt: ' : 'tool: ',
|
|
240
|
+
obs.kind === 'prompt' ? 'prompt: ' : obs.kind === 'response' ? 'response: ' : 'tool: ',
|
|
183
241
|
obs.tool_name || '',
|
|
184
242
|
obs.file_path ? ` file: ${obs.file_path}` : '',
|
|
185
243
|
obs.input ? `\ninput: ${obs.input}` : '',
|
|
186
244
|
obs.output ? `\noutput: ${obs.output}` : '',
|
|
187
245
|
].join('');
|
|
188
246
|
payload = {
|
|
189
|
-
|
|
247
|
+
record_type: 'observation',
|
|
190
248
|
scope: obs.scope,
|
|
191
249
|
project_id: obs.project_id,
|
|
250
|
+
project_ancestors: obs.project_id ? getProjectAncestors(obs.project_id) : [],
|
|
251
|
+
user_id: obs.user_id ?? null,
|
|
192
252
|
kind: obs.kind,
|
|
193
253
|
type: null,
|
|
194
254
|
task_type: null,
|
|
@@ -197,6 +257,7 @@ export async function drainEmbedQueue(
|
|
|
197
257
|
file_path: obs.file_path,
|
|
198
258
|
agent: obs.agent,
|
|
199
259
|
success: obs.failed === 0,
|
|
260
|
+
event_at: obs.event_at ?? null,
|
|
200
261
|
created_at: obs.created_at,
|
|
201
262
|
text,
|
|
202
263
|
};
|
|
@@ -207,7 +268,7 @@ export async function drainEmbedQueue(
|
|
|
207
268
|
.prepare('SELECT * FROM trajectories WHERE id = ?')
|
|
208
269
|
.get(item.record_id) as any;
|
|
209
270
|
if (!traj) {
|
|
210
|
-
markEmbedDone(item.record_id, item.
|
|
271
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
211
272
|
totalProcessed++;
|
|
212
273
|
continue;
|
|
213
274
|
}
|
|
@@ -220,9 +281,11 @@ export async function drainEmbedQueue(
|
|
|
220
281
|
success: traj.success === null || traj.success === undefined ? null : traj.success === 1,
|
|
221
282
|
});
|
|
222
283
|
payload = {
|
|
223
|
-
|
|
284
|
+
record_type: 'trajectory',
|
|
224
285
|
scope: traj.scope,
|
|
225
286
|
project_id: traj.project_id,
|
|
287
|
+
project_ancestors: traj.project_id ? getProjectAncestors(traj.project_id) : [],
|
|
288
|
+
user_id: traj.user_id ?? null,
|
|
226
289
|
kind: null,
|
|
227
290
|
type: null,
|
|
228
291
|
task_type: traj.task_type,
|
|
@@ -241,15 +304,17 @@ export async function drainEmbedQueue(
|
|
|
241
304
|
.prepare('SELECT * FROM notes WHERE id = ?')
|
|
242
305
|
.get(item.record_id) as any;
|
|
243
306
|
if (!note) {
|
|
244
|
-
markEmbedDone(item.record_id, item.
|
|
307
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
245
308
|
totalProcessed++;
|
|
246
309
|
continue;
|
|
247
310
|
}
|
|
248
311
|
text = `${note.title}\n\n${note.content}`;
|
|
249
312
|
payload = {
|
|
250
|
-
|
|
313
|
+
record_type: 'note',
|
|
251
314
|
scope: note.scope,
|
|
252
315
|
project_id: note.project_id,
|
|
316
|
+
project_ancestors: note.project_id ? getProjectAncestors(note.project_id) : [],
|
|
317
|
+
user_id: note.user_id ?? null,
|
|
253
318
|
kind: null,
|
|
254
319
|
type: note.type,
|
|
255
320
|
task_type: null,
|
|
@@ -258,6 +323,7 @@ export async function drainEmbedQueue(
|
|
|
258
323
|
file_path: null,
|
|
259
324
|
agent: note.author,
|
|
260
325
|
success: null,
|
|
326
|
+
event_at: note.event_at ?? null,
|
|
261
327
|
created_at: note.created_at,
|
|
262
328
|
text,
|
|
263
329
|
};
|
|
@@ -268,7 +334,7 @@ export async function drainEmbedQueue(
|
|
|
268
334
|
.prepare('SELECT * FROM summaries WHERE id = ?')
|
|
269
335
|
.get(item.record_id) as any;
|
|
270
336
|
if (!summary) {
|
|
271
|
-
markEmbedDone(item.record_id, item.
|
|
337
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
272
338
|
totalProcessed++;
|
|
273
339
|
continue;
|
|
274
340
|
}
|
|
@@ -277,9 +343,11 @@ export async function drainEmbedQueue(
|
|
|
277
343
|
.all(item.record_id) as Array<{ text: string }>;
|
|
278
344
|
text = claims.map((c) => c.text).join('\n');
|
|
279
345
|
payload = {
|
|
280
|
-
|
|
346
|
+
record_type: 'summary',
|
|
281
347
|
scope: summary.scope,
|
|
282
348
|
project_id: summary.project_id,
|
|
349
|
+
project_ancestors: summary.project_id ? getProjectAncestors(summary.project_id) : [],
|
|
350
|
+
user_id: summary.user_id ?? null,
|
|
283
351
|
kind: summary.kind,
|
|
284
352
|
type: null,
|
|
285
353
|
task_type: null,
|
|
@@ -293,67 +361,197 @@ export async function drainEmbedQueue(
|
|
|
293
361
|
};
|
|
294
362
|
break;
|
|
295
363
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
364
|
+
case 'entity': {
|
|
365
|
+
const entity = db
|
|
366
|
+
.prepare('SELECT * FROM entities WHERE id = ?')
|
|
367
|
+
.get(item.record_id) as any;
|
|
368
|
+
if (!entity) {
|
|
369
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
370
|
+
totalProcessed++;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
text = [entity.entity_type, entity.name, entity.description, entity.external_ref]
|
|
374
|
+
.filter(Boolean)
|
|
375
|
+
.join('\n');
|
|
376
|
+
payload = {
|
|
377
|
+
record_type: 'entity',
|
|
378
|
+
scope: entity.scope,
|
|
379
|
+
project_id: entity.project_id,
|
|
380
|
+
project_ancestors: entity.project_id ? getProjectAncestors(entity.project_id) : [],
|
|
381
|
+
user_id: entity.user_id ?? null,
|
|
382
|
+
entity_type: entity.entity_type,
|
|
383
|
+
kind: null,
|
|
384
|
+
type: null,
|
|
385
|
+
task_type: null,
|
|
386
|
+
note_ref: null,
|
|
387
|
+
task_ref: null,
|
|
388
|
+
file_path: null,
|
|
389
|
+
agent: null,
|
|
390
|
+
success: null,
|
|
391
|
+
created_at: entity.created_at,
|
|
392
|
+
text,
|
|
393
|
+
};
|
|
394
|
+
break;
|
|
317
395
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
396
|
+
case 'action': {
|
|
397
|
+
const action = db
|
|
398
|
+
.prepare('SELECT * FROM actions WHERE id = ?')
|
|
399
|
+
.get(item.record_id) as any;
|
|
400
|
+
if (!action) {
|
|
401
|
+
markEmbedDone(item.record_id, item.record_type, target);
|
|
402
|
+
totalProcessed++;
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
text = [action.title, action.description, action.blocked_reason]
|
|
406
|
+
.filter(Boolean)
|
|
407
|
+
.join('\n');
|
|
408
|
+
payload = {
|
|
409
|
+
record_type: 'action',
|
|
410
|
+
scope: action.scope,
|
|
411
|
+
project_id: action.project_id,
|
|
412
|
+
project_ancestors: action.project_id ? getProjectAncestors(action.project_id) : [],
|
|
413
|
+
user_id: action.user_id ?? null,
|
|
414
|
+
kind: action.status,
|
|
415
|
+
type: action.priority,
|
|
416
|
+
task_type: null,
|
|
417
|
+
note_ref: null,
|
|
418
|
+
task_ref: null,
|
|
419
|
+
file_path: null,
|
|
420
|
+
agent: null,
|
|
421
|
+
success: null,
|
|
422
|
+
created_at: toUnixSeconds(action.created_at),
|
|
423
|
+
text,
|
|
424
|
+
};
|
|
425
|
+
break;
|
|
325
426
|
}
|
|
326
427
|
}
|
|
327
428
|
|
|
328
|
-
|
|
329
|
-
totalProcessed++;
|
|
429
|
+
preparedItems.push({ item, text, payload });
|
|
330
430
|
} catch (err) {
|
|
331
431
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
332
|
-
if (err instanceof EmbeddingConfigurationError) {
|
|
333
|
-
// The embedder itself is unavailable (e.g. the optional local embedder
|
|
334
|
-
// is not installed). No record is at fault: put this item and the rest
|
|
335
|
-
// of the batch back to pending and stop until it is fixed.
|
|
336
|
-
for (const pending of items.slice(itemIdx)) {
|
|
337
|
-
releaseEmbedClaim(pending.record_id, pending.grain, target, errorMsg);
|
|
338
|
-
}
|
|
339
|
-
logger.error({ target, error: errorMsg }, 'embedder unavailable; queue left pending');
|
|
340
|
-
embedderUnavailable = true;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
432
|
logger.error(
|
|
344
433
|
{
|
|
345
434
|
recordId: item.record_id,
|
|
346
|
-
|
|
435
|
+
record_type: item.record_type,
|
|
347
436
|
target,
|
|
348
437
|
error: errorMsg,
|
|
349
438
|
},
|
|
350
|
-
'error
|
|
439
|
+
'error preparing record for embedding'
|
|
351
440
|
);
|
|
352
|
-
markEmbedFailed(item.record_id, item.
|
|
441
|
+
markEmbedFailed(item.record_id, item.record_type, target, errorMsg);
|
|
353
442
|
totalFailed++;
|
|
354
443
|
}
|
|
444
|
+
}
|
|
355
445
|
|
|
356
|
-
|
|
446
|
+
if (preparedItems.length > 0) {
|
|
447
|
+
const persistVector = (
|
|
448
|
+
prepared: (typeof preparedItems)[number],
|
|
449
|
+
vector: number[]
|
|
450
|
+
): void => {
|
|
451
|
+
let queuedForQdrant = false;
|
|
452
|
+
const blob = serializeEmbedding(vector);
|
|
453
|
+
|
|
454
|
+
const blobTable = EMBEDDING_TABLE_BY_TYPE[prepared.item.record_type];
|
|
455
|
+
if (blobTable) {
|
|
456
|
+
if (!skipSqliteBlobUpdate) {
|
|
457
|
+
db.prepare(`UPDATE ${blobTable} SET embedding = ? WHERE id = ?`).run(
|
|
458
|
+
blob,
|
|
459
|
+
prepared.item.record_id
|
|
460
|
+
);
|
|
461
|
+
} else if (options?.onVectorsComputed) {
|
|
462
|
+
computedBlobs.push({
|
|
463
|
+
id: prepared.item.record_id,
|
|
464
|
+
record_type: prepared.item.record_type,
|
|
465
|
+
blob,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (qdrant && vector.length > 0) {
|
|
471
|
+
qdrantPointsToUpsert.push({
|
|
472
|
+
id: toQdrantPointId(prepared.item.record_id),
|
|
473
|
+
vector,
|
|
474
|
+
payload: { ...prepared.payload, record_id: prepared.item.record_id },
|
|
475
|
+
});
|
|
476
|
+
pendingQdrantDone.push({
|
|
477
|
+
record_id: prepared.item.record_id,
|
|
478
|
+
record_type: prepared.item.record_type,
|
|
479
|
+
});
|
|
480
|
+
queuedForQdrant = true;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (!queuedForQdrant) {
|
|
484
|
+
markEmbedDone(prepared.item.record_id, prepared.item.record_type, target);
|
|
485
|
+
totalProcessed++;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
if (recipe.embed_tier === 'none') {
|
|
490
|
+
for (const prepared of preparedItems) {
|
|
491
|
+
markEmbedDone(prepared.item.record_id, prepared.item.record_type, target);
|
|
492
|
+
totalProcessed++;
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
let batchVectors: number[][] | null = null;
|
|
496
|
+
try {
|
|
497
|
+
batchVectors = await embedDocuments(preparedItems.map((p) => p.text));
|
|
498
|
+
} catch (err) {
|
|
499
|
+
if (err instanceof EmbeddingConfigurationError) {
|
|
500
|
+
for (const pending of preparedItems) {
|
|
501
|
+
releaseEmbedClaim(pending.item.record_id, pending.item.record_type, target, err.message);
|
|
502
|
+
}
|
|
503
|
+
logger.error({ target, error: err.message }, 'embedder unavailable; queue left pending');
|
|
504
|
+
embedderUnavailable = true;
|
|
505
|
+
} else {
|
|
506
|
+
// Fall back to per-item embedding so one bad payload never fails the whole batch
|
|
507
|
+
logger.warn(
|
|
508
|
+
{
|
|
509
|
+
target,
|
|
510
|
+
count: preparedItems.length,
|
|
511
|
+
error: err instanceof Error ? err.message : String(err),
|
|
512
|
+
},
|
|
513
|
+
'batch embedding failed; falling back to per-item embedding'
|
|
514
|
+
);
|
|
515
|
+
for (let idx = 0; idx < preparedItems.length; idx++) {
|
|
516
|
+
const prepared = preparedItems[idx];
|
|
517
|
+
try {
|
|
518
|
+
const vector = await embedDocument(prepared.text);
|
|
519
|
+
persistVector(prepared, vector);
|
|
520
|
+
} catch (itemErr) {
|
|
521
|
+
const errorMsg = itemErr instanceof Error ? itemErr.message : String(itemErr);
|
|
522
|
+
if (itemErr instanceof EmbeddingConfigurationError) {
|
|
523
|
+
for (const pending of preparedItems.slice(idx)) {
|
|
524
|
+
releaseEmbedClaim(pending.item.record_id, pending.item.record_type, target, errorMsg);
|
|
525
|
+
}
|
|
526
|
+
logger.error({ target, error: errorMsg }, 'embedder unavailable; queue left pending');
|
|
527
|
+
embedderUnavailable = true;
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
logger.error(
|
|
531
|
+
{
|
|
532
|
+
recordId: prepared.item.record_id,
|
|
533
|
+
record_type: prepared.item.record_type,
|
|
534
|
+
target,
|
|
535
|
+
error: errorMsg,
|
|
536
|
+
},
|
|
537
|
+
'error embedding record'
|
|
538
|
+
);
|
|
539
|
+
markEmbedFailed(prepared.item.record_id, prepared.item.record_type, target, errorMsg);
|
|
540
|
+
totalFailed++;
|
|
541
|
+
}
|
|
542
|
+
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (batchVectors) {
|
|
548
|
+
for (let idx = 0; idx < preparedItems.length; idx++) {
|
|
549
|
+
persistVector(preparedItems[idx], batchVectors[idx] ?? []);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Yield to the event loop between batches so HTTP health/dashboard requests stay responsive
|
|
357
555
|
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
358
556
|
}
|
|
359
557
|
|
|
@@ -361,24 +559,29 @@ export async function drainEmbedQueue(
|
|
|
361
559
|
if (qdrant && qdrantPointsToUpsert.length > 0) {
|
|
362
560
|
const targetCollection =
|
|
363
561
|
target === 'live' ? getStoreMeta()?.qdrant_alias || 'brain' : target;
|
|
562
|
+
let upsertSucceeded = false;
|
|
563
|
+
let upsertErrMsg = '';
|
|
364
564
|
try {
|
|
365
565
|
await qdrant.upsert(targetCollection, {
|
|
366
566
|
points: qdrantPointsToUpsert,
|
|
367
567
|
});
|
|
568
|
+
upsertSucceeded = true;
|
|
368
569
|
} catch (qdrantErr: any) {
|
|
369
570
|
// If collection was not created yet (e.g. freshly started Qdrant container), create it and retry once
|
|
370
|
-
|
|
371
|
-
if (recipe.embed_dim > 0 && (qdrantErr?.status === 404 ||
|
|
571
|
+
upsertErrMsg = qdrantErr instanceof Error ? qdrantErr.message : String(qdrantErr);
|
|
572
|
+
if (recipe.embed_dim > 0 && (qdrantErr?.status === 404 || upsertErrMsg.toLowerCase().includes('not found'))) {
|
|
372
573
|
try {
|
|
373
574
|
await createQdrantCollectionWithIndexes(qdrant, targetCollection, recipe.embed_dim);
|
|
374
575
|
await qdrant.upsert(targetCollection, {
|
|
375
576
|
points: qdrantPointsToUpsert,
|
|
376
577
|
});
|
|
578
|
+
upsertSucceeded = true;
|
|
377
579
|
} catch (retryErr) {
|
|
580
|
+
upsertErrMsg = retryErr instanceof Error ? retryErr.message : String(retryErr);
|
|
378
581
|
logger.warn(
|
|
379
582
|
{
|
|
380
583
|
collection: targetCollection,
|
|
381
|
-
error:
|
|
584
|
+
error: upsertErrMsg,
|
|
382
585
|
},
|
|
383
586
|
'qdrant batch upsert retry after collection creation failed'
|
|
384
587
|
);
|
|
@@ -389,12 +592,29 @@ export async function drainEmbedQueue(
|
|
|
389
592
|
{
|
|
390
593
|
collection: targetCollection,
|
|
391
594
|
count: qdrantPointsToUpsert.length,
|
|
392
|
-
error:
|
|
595
|
+
error: upsertErrMsg,
|
|
393
596
|
},
|
|
394
597
|
'qdrant batch upsert skipped or failed'
|
|
395
598
|
);
|
|
396
599
|
}
|
|
397
600
|
}
|
|
601
|
+
|
|
602
|
+
if (upsertSucceeded || !qdrantConfigured) {
|
|
603
|
+
for (const p of pendingQdrantDone) {
|
|
604
|
+
markEmbedDone(p.record_id, p.record_type, target);
|
|
605
|
+
totalProcessed++;
|
|
606
|
+
}
|
|
607
|
+
if (options?.onVectorsComputed && computedBlobs.length > 0) {
|
|
608
|
+
options.onVectorsComputed(computedBlobs);
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
for (const p of pendingQdrantDone) {
|
|
612
|
+
markEmbedFailed(p.record_id, p.record_type, target, upsertErrMsg || 'Qdrant upsert failed');
|
|
613
|
+
totalFailed++;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
} else if (options?.onVectorsComputed && computedBlobs.length > 0) {
|
|
617
|
+
options.onVectorsComputed(computedBlobs);
|
|
398
618
|
}
|
|
399
619
|
}
|
|
400
620
|
|
|
@@ -421,7 +641,16 @@ export async function ensureInitialEmbeddingsSync(options?: {
|
|
|
421
641
|
try {
|
|
422
642
|
const targetCollection = getStoreMeta()?.qdrant_alias || 'brain';
|
|
423
643
|
const collections = await qdrant.getCollections();
|
|
424
|
-
|
|
644
|
+
// After a re-embed, `brain` is an alias onto brain_v_<ts>, and
|
|
645
|
+
// getCollections lists only real collections. Treat an alias as existing:
|
|
646
|
+
// creating a collection under an alias's name is a 400 from Qdrant, which
|
|
647
|
+
// used to abort this whole probe on every start of a re-embedded store.
|
|
648
|
+
const aliasesRes = typeof (qdrant as any).getAliases === 'function'
|
|
649
|
+
? await (qdrant as any).getAliases().catch(() => null)
|
|
650
|
+
: null;
|
|
651
|
+
const collectionExists =
|
|
652
|
+
collections.collections.some((c) => c.name === targetCollection) ||
|
|
653
|
+
Boolean(aliasesRes?.aliases?.some((a: any) => a.alias_name === targetCollection));
|
|
425
654
|
|
|
426
655
|
if (!collectionExists) {
|
|
427
656
|
await createQdrantCollectionWithIndexes(qdrant, targetCollection, recipe.embed_dim);
|
|
@@ -481,7 +710,10 @@ export async function createQdrantCollectionWithIndexes(
|
|
|
481
710
|
const keywordFields = [
|
|
482
711
|
'scope',
|
|
483
712
|
'project_id',
|
|
484
|
-
'
|
|
713
|
+
'project_ancestors',
|
|
714
|
+
'user_id',
|
|
715
|
+
'entity_type',
|
|
716
|
+
'record_type',
|
|
485
717
|
'kind',
|
|
486
718
|
'type',
|
|
487
719
|
'task_type',
|
|
@@ -561,8 +793,16 @@ export async function startReembed(options?: {
|
|
|
561
793
|
const trajRows = db.prepare('SELECT id FROM trajectories').all() as Array<{ id: string }>;
|
|
562
794
|
const obsRows = db.prepare('SELECT id FROM observations').all() as Array<{ id: string }>;
|
|
563
795
|
const sumRows = db.prepare('SELECT id FROM summaries WHERE is_latest = 1').all() as Array<{ id: string }>;
|
|
796
|
+
const entityRows = db.prepare('SELECT id FROM entities').all() as Array<{ id: string }>;
|
|
797
|
+
const actionRows = db.prepare('SELECT id FROM actions').all() as Array<{ id: string }>;
|
|
564
798
|
|
|
565
|
-
activeReembedStatus.total =
|
|
799
|
+
activeReembedStatus.total =
|
|
800
|
+
noteRows.length +
|
|
801
|
+
trajRows.length +
|
|
802
|
+
obsRows.length +
|
|
803
|
+
sumRows.length +
|
|
804
|
+
entityRows.length +
|
|
805
|
+
actionRows.length;
|
|
566
806
|
|
|
567
807
|
// Enqueue to embed_queue with target = newCollectionName in a single atomic transaction (CR-11)
|
|
568
808
|
transaction(db, () => {
|
|
@@ -570,12 +810,16 @@ export async function startReembed(options?: {
|
|
|
570
810
|
for (const r of trajRows) enqueueForEmbedding(r.id, 'trajectory', newCollectionName);
|
|
571
811
|
for (const r of obsRows) enqueueForEmbedding(r.id, 'observation', newCollectionName);
|
|
572
812
|
for (const r of sumRows) enqueueForEmbedding(r.id, 'summary', newCollectionName);
|
|
813
|
+
for (const r of entityRows) enqueueForEmbedding(r.id, 'entity', newCollectionName);
|
|
814
|
+
for (const r of actionRows) enqueueForEmbedding(r.id, 'action', newCollectionName);
|
|
573
815
|
})();
|
|
574
816
|
|
|
575
817
|
// Create new collection in Qdrant if reachable
|
|
818
|
+
let qdrantCollectionReady = false;
|
|
576
819
|
if (qdrant && recipe.embed_dim > 0) {
|
|
577
820
|
try {
|
|
578
821
|
await createQdrantCollectionWithIndexes(qdrant, newCollectionName, recipe.embed_dim);
|
|
822
|
+
qdrantCollectionReady = true;
|
|
579
823
|
} catch (qdrantErr) {
|
|
580
824
|
logger.warn(
|
|
581
825
|
{ error: qdrantErr instanceof Error ? qdrantErr.message : String(qdrantErr) },
|
|
@@ -592,6 +836,7 @@ export async function startReembed(options?: {
|
|
|
592
836
|
// Drain queue for new collection until empty
|
|
593
837
|
let processedTotal = 0;
|
|
594
838
|
let failedTotal = 0;
|
|
839
|
+
const deferredBlobs: Array<{ id: string; record_type: EmbedRecordType; blob: Buffer }> = [];
|
|
595
840
|
|
|
596
841
|
while (true) {
|
|
597
842
|
const { processed, failed, remaining } = await drainEmbedQueue({
|
|
@@ -599,6 +844,10 @@ export async function startReembed(options?: {
|
|
|
599
844
|
batchSize: 50,
|
|
600
845
|
maxBatches: 1,
|
|
601
846
|
client: qdrant ?? undefined,
|
|
847
|
+
skipSqliteBlobUpdate: true,
|
|
848
|
+
onVectorsComputed: (blobs) => {
|
|
849
|
+
deferredBlobs.push(...blobs);
|
|
850
|
+
},
|
|
602
851
|
});
|
|
603
852
|
|
|
604
853
|
processedTotal += processed;
|
|
@@ -607,14 +856,22 @@ export async function startReembed(options?: {
|
|
|
607
856
|
activeReembedStatus.failed = failedTotal;
|
|
608
857
|
|
|
609
858
|
if (remaining === 0) break;
|
|
859
|
+
if (processed === 0 && failed === 0) {
|
|
860
|
+
throw new Error(`Reembed stalled for target '${newCollectionName}' with ${remaining} remaining items`);
|
|
861
|
+
}
|
|
610
862
|
}
|
|
611
863
|
|
|
612
864
|
// Switch alias in Qdrant if reachable
|
|
613
865
|
const meta = getStoreMeta();
|
|
614
866
|
const aliasName = meta?.qdrant_alias || 'brain';
|
|
615
867
|
|
|
616
|
-
if (qdrant) {
|
|
617
|
-
|
|
868
|
+
if (qdrant && recipe.embed_dim > 0 && qdrantCollectionReady) {
|
|
869
|
+
const collections = await qdrant.getCollections();
|
|
870
|
+
const isRegularCollection = collections.collections.some((c) => c.name === aliasName);
|
|
871
|
+
if (isRegularCollection) {
|
|
872
|
+
// Cannot create an alias with the same name as an existing regular collection;
|
|
873
|
+
// delete the old regular collection before creating the alias.
|
|
874
|
+
await qdrant.deleteCollection(aliasName);
|
|
618
875
|
await qdrant.updateCollectionAliases({
|
|
619
876
|
actions: [
|
|
620
877
|
{
|
|
@@ -625,13 +882,35 @@ export async function startReembed(options?: {
|
|
|
625
882
|
},
|
|
626
883
|
],
|
|
627
884
|
});
|
|
628
|
-
}
|
|
629
|
-
|
|
885
|
+
} else {
|
|
886
|
+
const aliasesRes = typeof (qdrant as any).getAliases === 'function'
|
|
887
|
+
? await (qdrant as any).getAliases().catch(() => null)
|
|
888
|
+
: null;
|
|
889
|
+
const hasAlias = aliasesRes?.aliases?.some((a: any) => a.alias_name === aliasName);
|
|
890
|
+
const actions: any[] = [];
|
|
891
|
+
if (hasAlias) {
|
|
892
|
+
actions.push({ delete_alias: { alias_name: aliasName } });
|
|
893
|
+
}
|
|
894
|
+
actions.push({
|
|
895
|
+
create_alias: {
|
|
896
|
+
collection_name: newCollectionName,
|
|
897
|
+
alias_name: aliasName,
|
|
898
|
+
},
|
|
899
|
+
});
|
|
900
|
+
await qdrant.updateCollectionAliases({ actions });
|
|
630
901
|
}
|
|
631
902
|
}
|
|
632
903
|
|
|
633
|
-
//
|
|
634
|
-
|
|
904
|
+
// Apply deferred SQLite embedding BLOB updates and store_meta atomically on success
|
|
905
|
+
transaction(db, () => {
|
|
906
|
+
for (const item of deferredBlobs) {
|
|
907
|
+
const table = EMBEDDING_TABLE_BY_TYPE[item.record_type];
|
|
908
|
+
if (table) {
|
|
909
|
+
db.prepare(`UPDATE ${table} SET embedding = ? WHERE id = ?`).run(item.blob, item.id);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
commitStoreMeta(recipe, aliasName);
|
|
913
|
+
})();
|
|
635
914
|
|
|
636
915
|
activeReembedStatus.status = 'completed';
|
|
637
916
|
activeReembedStatus.completed_at = Math.floor(Date.now() / 1000);
|
|
@@ -643,6 +922,7 @@ export async function startReembed(options?: {
|
|
|
643
922
|
};
|
|
644
923
|
} catch (error) {
|
|
645
924
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
925
|
+
clearEmbedQueueTarget(newCollectionName);
|
|
646
926
|
activeReembedStatus.status = 'failed';
|
|
647
927
|
activeReembedStatus.error = errorMsg;
|
|
648
928
|
logger.error({ error: errorMsg }, 'reembed failed');
|