@exulu/backend 1.70.0 → 2.0.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.
Files changed (47) hide show
  1. package/dist/{catalog-TBSPSN2N.js → catalog-UGTDNMDM.js} +2 -1
  2. package/dist/{chunk-YCE44CMU.js → chunk-7CCMW3IW.js} +2 -0
  3. package/dist/chunk-IJ4HNHOT.js +6416 -0
  4. package/dist/{chunk-IDHS2BZO.js → chunk-T6JVFT7L.js} +2 -0
  5. package/dist/cli/start-whisper.cjs +1 -0
  6. package/dist/cli/start-whisper.js +2 -1
  7. package/dist/convert-exulu-tools-to-ai-sdk-tools-2PEDFZ2X.js +9 -0
  8. package/dist/index.cjs +9568 -9245
  9. package/dist/index.d.cts +46 -29
  10. package/dist/index.d.ts +46 -29
  11. package/dist/index.js +5016 -549
  12. package/ee/agentic-retrieval/pipeline/config.test.ts +81 -0
  13. package/ee/agentic-retrieval/pipeline/config.ts +189 -0
  14. package/ee/agentic-retrieval/pipeline/hyde.test.ts +55 -0
  15. package/ee/agentic-retrieval/pipeline/hyde.ts +133 -0
  16. package/ee/agentic-retrieval/pipeline/index.test.ts +140 -0
  17. package/ee/agentic-retrieval/pipeline/index.ts +638 -0
  18. package/ee/agentic-retrieval/pipeline/memory.test.ts +101 -0
  19. package/ee/agentic-retrieval/pipeline/memory.ts +566 -0
  20. package/ee/agentic-retrieval/pipeline/multi-query.test.ts +51 -0
  21. package/ee/agentic-retrieval/pipeline/multi-query.ts +158 -0
  22. package/ee/agentic-retrieval/pipeline/prefilter.test.ts +93 -0
  23. package/ee/agentic-retrieval/pipeline/prefilter.ts +389 -0
  24. package/ee/agentic-retrieval/pipeline/rerank.test.ts +128 -0
  25. package/ee/agentic-retrieval/pipeline/rerank.ts +178 -0
  26. package/ee/agentic-retrieval/pipeline/routing.test.ts +144 -0
  27. package/ee/agentic-retrieval/pipeline/routing.ts +343 -0
  28. package/ee/agentic-retrieval/pipeline/search.test.ts +149 -0
  29. package/ee/agentic-retrieval/pipeline/search.ts +180 -0
  30. package/ee/agentic-retrieval/pipeline/text-utils.test.ts +43 -0
  31. package/ee/agentic-retrieval/pipeline/text-utils.ts +85 -0
  32. package/ee/agentic-retrieval/pipeline/types.ts +59 -0
  33. package/ee/python/documents/processing/doc_processor.ts +1 -1
  34. package/ee/python/documents/processing/split_pdf.py +78 -24
  35. package/package.json +2 -1
  36. package/dist/chunk-WCP3WZM3.js +0 -10391
  37. package/dist/convert-exulu-tools-to-ai-sdk-tools-GQ3UIYP7.js +0 -6
  38. package/ee/agentic-retrieval/v3/agent-loop.ts +0 -288
  39. package/ee/agentic-retrieval/v3/classifier.ts +0 -92
  40. package/ee/agentic-retrieval/v3/context-sampler.ts +0 -79
  41. package/ee/agentic-retrieval/v3/dynamic-tools.ts +0 -115
  42. package/ee/agentic-retrieval/v3/index.ts +0 -471
  43. package/ee/agentic-retrieval/v3/session-tools-registry.ts +0 -20
  44. package/ee/agentic-retrieval/v3/strategies.ts +0 -171
  45. package/ee/agentic-retrieval/v3/tools.ts +0 -558
  46. package/ee/agentic-retrieval/v3/trajectory.ts +0 -309
  47. package/ee/agentic-retrieval/v3/types.ts +0 -59
@@ -1,309 +0,0 @@
1
- import * as fs from "fs/promises";
2
- import * as path from "path";
3
- import type { AgenticRetrievalOutput, ClassificationResult, ChunkResult } from "./types";
4
-
5
- export const trajectoryRegistry = {
6
- lastFile: undefined as string | undefined,
7
- };
8
-
9
- export interface TrajectoryStepData {
10
- stepNumber: number;
11
- systemPrompt: string;
12
- text: string;
13
- toolCalls: Array<{
14
- name: string;
15
- id: string;
16
- input: any;
17
- output?: any;
18
- }>;
19
- chunks: ChunkResult[];
20
- dynamicToolsCreated: string[];
21
- tokens: number;
22
- }
23
-
24
- interface TrajectoryData {
25
- timestamp: string;
26
- query: string;
27
- classification: ClassificationResult;
28
- preselectedItemIds?: string[];
29
- steps: {
30
- step_number: number;
31
- text: string;
32
- tool_calls: { name: string; id: string; input: any }[];
33
- chunks_retrieved: number;
34
- dynamic_tools_created: string[];
35
- tokens: number;
36
- }[];
37
- final: {
38
- total_chunks: number;
39
- total_steps: number;
40
- total_tokens: number;
41
- duration_ms: number;
42
- success: boolean;
43
- error?: string;
44
- };
45
- }
46
-
47
- export class TrajectoryLogger {
48
- private data: TrajectoryData;
49
- private richSteps: TrajectoryStepData[] = [];
50
- private startTime = Date.now();
51
- private logDir: string;
52
-
53
- constructor(
54
- query: string,
55
- classification: ClassificationResult,
56
- logDir = path.join(process.cwd(), "ee/agentic-retrieval/logs"),
57
- preselectedItemIds?: string[],
58
- ) {
59
- this.logDir = logDir;
60
- this.data = {
61
- timestamp: new Date().toISOString(),
62
- query,
63
- classification,
64
- preselectedItemIds: preselectedItemIds?.length ? preselectedItemIds : undefined,
65
- steps: [],
66
- final: {
67
- total_chunks: 0,
68
- total_steps: 0,
69
- total_tokens: 0,
70
- duration_ms: 0,
71
- success: false,
72
- },
73
- };
74
- }
75
-
76
- recordStep(step: AgenticRetrievalOutput["steps"][0]): void {
77
- this.data.steps.push({
78
- step_number: step.stepNumber,
79
- text: step.text,
80
- tool_calls: step.toolCalls,
81
- chunks_retrieved: step.chunks.length,
82
- dynamic_tools_created: step.dynamicToolsCreated,
83
- tokens: step.tokens,
84
- });
85
- }
86
-
87
- recordRichStep(data: TrajectoryStepData): void {
88
- this.richSteps.push(data);
89
- }
90
-
91
- private toMarkdown(durationMs: number, success: boolean, error?: Error): string {
92
- const totalTokens = this.richSteps.reduce((sum, s) => sum + s.tokens, 0);
93
- const totalChunks = this.richSteps.reduce((sum, s) => sum + s.chunks.length, 0);
94
- const status = success ? "✓ Success" : `✗ Failed${error ? `: ${error.message}` : ""}`;
95
- const lines: string[] = [];
96
-
97
- // ── Header ──────────────────────────────────────────────────────────────
98
- lines.push(`# Agentic Retrieval — ${this.data.timestamp}`);
99
- lines.push("");
100
- lines.push(`**Query:** ${this.data.query} `);
101
- lines.push(
102
- `**Duration:** ${(durationMs / 1000).toFixed(1)}s | **Tokens:** ${totalTokens} | **Status:** ${status}`,
103
- );
104
- lines.push("");
105
-
106
- // ── Classification ───────────────────────────────────────────────────────
107
- lines.push("## Classification");
108
- lines.push("");
109
- lines.push(`- **Type:** \`${this.data.classification.queryType}\``);
110
- lines.push(`- **Language:** \`${this.data.classification.language}\``);
111
- const suggested = this.data.classification.suggestedContextIds;
112
- lines.push(
113
- `- **Suggested contexts:** ${suggested.length > 0 ? suggested.map((id) => `\`${id}\``).join(", ") : "*(all)*"}`,
114
- );
115
- if (this.data.preselectedItemIds?.length) {
116
- lines.push(
117
- `- **Preselected item IDs:** ${this.data.preselectedItemIds.map((id) => `\`${id}\``).join(", ")}`,
118
- );
119
- }
120
- lines.push("");
121
- lines.push("---");
122
- lines.push("");
123
-
124
- // ── System prompt (from step 1, collapsed) ───────────────────────────────
125
- const firstStep = this.richSteps[0];
126
- if (firstStep) {
127
- lines.push("## System Prompt");
128
- lines.push("");
129
- lines.push("<details>");
130
- lines.push("<summary>View system prompt</summary>");
131
- lines.push("");
132
- lines.push("```");
133
- lines.push(firstStep.systemPrompt);
134
- lines.push("```");
135
- lines.push("");
136
- lines.push("</details>");
137
- lines.push("");
138
- lines.push("---");
139
- lines.push("");
140
- }
141
-
142
- // ── Steps ────────────────────────────────────────────────────────────────
143
- for (const step of this.richSteps) {
144
- const toolLabel =
145
- step.toolCalls.map((tc) => `\`${tc.name}\``).join(", ") || "*(no tool calls)*";
146
- lines.push(`## Step ${step.stepNumber} — ${toolLabel}`);
147
- lines.push("");
148
- const dynLabel =
149
- step.dynamicToolsCreated.length > 0
150
- ? step.dynamicToolsCreated.map((t) => `\`${t}\``).join(", ")
151
- : "none";
152
- lines.push(
153
- `**Tokens:** ${step.tokens} | **Chunks retrieved:** ${step.chunks.length} | **Dynamic tools created:** ${dynLabel}`,
154
- );
155
- lines.push("");
156
-
157
- // Reasoning
158
- if (step.text) {
159
- lines.push("### Reasoning");
160
- lines.push("");
161
- lines.push(step.text);
162
- lines.push("");
163
- }
164
-
165
- // Tool calls
166
- if (step.toolCalls.length > 0) {
167
- lines.push("### Tool Calls");
168
- lines.push("");
169
- for (const [i, tc] of step.toolCalls.entries()) {
170
- lines.push(`#### ${i + 1}. \`${tc.name}\``);
171
- lines.push("");
172
- lines.push("**Input:**");
173
- lines.push("```json");
174
- lines.push(JSON.stringify(tc.input, null, 2));
175
- lines.push("```");
176
- lines.push("");
177
-
178
- if (tc.output !== undefined) {
179
- let parsedOutput: any;
180
- try {
181
- parsedOutput =
182
- typeof tc.output === "string" ? JSON.parse(tc.output) : tc.output;
183
- } catch {
184
- parsedOutput = tc.output;
185
- }
186
- const outputStr = JSON.stringify(parsedOutput, null, 2);
187
- const truncated = outputStr.length > 2000;
188
- lines.push("**Output:**");
189
- lines.push("```json");
190
- lines.push(truncated ? `${outputStr.slice(0, 2000)}\n… (truncated)` : outputStr);
191
- lines.push("```");
192
- lines.push("");
193
- }
194
- }
195
- }
196
-
197
- // Chunks table
198
- if (step.chunks.length > 0) {
199
- lines.push("### Chunks Retrieved");
200
- lines.push("");
201
- lines.push("| # | Item | Context | Chunk | Score |");
202
- lines.push("|---|------|---------|-------|-------|");
203
- for (const [i, c] of step.chunks.entries()) {
204
- const score =
205
- c.metadata?.hybrid_score ??
206
- c.metadata?.cosine_distance ??
207
- c.metadata?.fts_rank ??
208
- "—";
209
- const scoreStr = typeof score === "number" ? score.toFixed(4) : String(score);
210
- lines.push(
211
- `| ${i + 1} | ${c.item_name ?? "—"} | \`${c.context}\` | ${c.chunk_index ?? "—"} | ${scoreStr} |`,
212
- );
213
- }
214
- lines.push("");
215
-
216
- const withContent = step.chunks.filter((c) => c.chunk_content);
217
- if (withContent.length > 0) {
218
- lines.push("<details>");
219
- lines.push("<summary>View chunk content</summary>");
220
- lines.push("");
221
- for (const c of withContent) {
222
- lines.push(`**${c.item_name} (chunk ${c.chunk_index}):**`);
223
- lines.push("");
224
- const content = (c.chunk_content ?? "").trim();
225
- lines.push(`> ${content.split("\n").join("\n> ")}`);
226
- lines.push("");
227
- }
228
- lines.push("</details>");
229
- lines.push("");
230
- }
231
- }
232
-
233
- // Per-step system prompt addendum (only when it differs from step 1)
234
- if (firstStep && step.stepNumber > 1 && step.systemPrompt !== firstStep.systemPrompt) {
235
- const addendum = step.systemPrompt.slice(firstStep.systemPrompt.length).trim();
236
- if (addendum) {
237
- lines.push("<details>");
238
- lines.push("<summary>System prompt addendum (this step only)</summary>");
239
- lines.push("");
240
- lines.push("```");
241
- lines.push(addendum);
242
- lines.push("```");
243
- lines.push("");
244
- lines.push("</details>");
245
- lines.push("");
246
- }
247
- }
248
-
249
- lines.push("---");
250
- lines.push("");
251
- }
252
-
253
- // ── Summary ──────────────────────────────────────────────────────────────
254
- lines.push("## Summary");
255
- lines.push("");
256
- lines.push("| Metric | Value |");
257
- lines.push("|--------|-------|");
258
- lines.push(`| Steps | ${this.richSteps.length} |`);
259
- lines.push(`| Total chunks | ${totalChunks} |`);
260
- lines.push(`| Total tokens | ${totalTokens} |`);
261
- lines.push(`| Duration | ${(durationMs / 1000).toFixed(1)}s |`);
262
- lines.push(`| Status | ${status} |`);
263
- if (error) {
264
- lines.push(`| Error | ${error.message} |`);
265
- }
266
- lines.push("");
267
-
268
- return lines.join("\n");
269
- }
270
-
271
- async finalize(
272
- output: AgenticRetrievalOutput,
273
- success: boolean,
274
- error?: Error,
275
- writeFiles = false,
276
- ): Promise<string | undefined> {
277
- const durationMs = Date.now() - this.startTime;
278
-
279
- this.data.final = {
280
- total_chunks: output.chunks.length,
281
- total_steps: output.steps.length,
282
- total_tokens: output.totalTokens,
283
- duration_ms: durationMs,
284
- success,
285
- error: error?.message,
286
- };
287
-
288
- if (!writeFiles) return undefined;
289
-
290
- try {
291
- await fs.mkdir(this.logDir, { recursive: true });
292
- const ts = Date.now();
293
- const jsonPath = path.join(this.logDir, `trajectory_${ts}.json`);
294
- const mdPath = path.join(this.logDir, `trajectory_${ts}.md`);
295
-
296
- await Promise.all([
297
- fs.writeFile(jsonPath, JSON.stringify(this.data, null, 2), "utf-8"),
298
- fs.writeFile(mdPath, this.toMarkdown(durationMs, success, error), "utf-8"),
299
- ]);
300
-
301
- console.log(`[EXULU] v3 trajectory saved: trajectory_${ts}.json + trajectory_${ts}.md`);
302
- trajectoryRegistry.lastFile = jsonPath;
303
- return jsonPath;
304
- } catch (e) {
305
- console.error("[EXULU] v3 failed to write trajectory:", e);
306
- return undefined;
307
- }
308
- }
309
- }
@@ -1,59 +0,0 @@
1
- export type QueryType = "aggregate" | "list" | "targeted" | "exploratory";
2
-
3
- export interface ClassificationResult {
4
- queryType: QueryType;
5
- language: string;
6
- /** IDs of contexts most likely relevant. Empty means search all. */
7
- suggestedContextIds: string[];
8
- }
9
-
10
- export interface ContextSample {
11
- contextId: string;
12
- contextName: string;
13
- /** All field names available on items (standard + custom) */
14
- fields: string[];
15
- /** Up to 2 example item records */
16
- exampleItems: Array<Record<string, any>>;
17
- sampledAt: number;
18
- }
19
-
20
- export interface ChunkResult {
21
- item_name: string;
22
- item_id: string;
23
- context: string;
24
- chunk_id?: string;
25
- chunk_index?: number;
26
- chunk_content?: string;
27
- metadata?: Record<string, any>;
28
- }
29
-
30
- export interface RetrievalStep {
31
- stepNumber: number;
32
- /** Text the model output during this step (reasoning) */
33
- text: string;
34
- toolCalls: Array<{ name: string; id: string; input: any }>;
35
- chunks: ChunkResult[];
36
- dynamicToolsCreated: string[];
37
- tokens: number;
38
- }
39
-
40
- interface Reasoning {
41
- text: string;
42
- tools: {
43
- name: string;
44
- id: string;
45
- input: any;
46
- output: any;
47
- }[]
48
- }
49
-
50
- export interface AgenticRetrievalOutput {
51
- steps: RetrievalStep[];
52
- reasoning: Reasoning[];
53
- /** All chunks collected across all steps */
54
- chunks: ChunkResult[];
55
- usage: any[];
56
- totalTokens: number;
57
- /** Path to the trajectory JSON file written to disk, if any */
58
- trajectoryFile?: string;
59
- }