@exulu/backend 5.8.2 → 5.10.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/dist/{chunk-NUEM3HMI.js → chunk-H6TI5MQL.js} +717 -178
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-3UCQOIY6.js → convert-exulu-tools-to-ai-sdk-tools-56EULD5M.js} +1 -1
- package/dist/index.cjs +1268 -423
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +311 -23
- package/ee/agentic-retrieval/pipeline/index.test.ts +47 -0
- package/ee/agentic-retrieval/pipeline/index.ts +28 -0
- package/ee/agentic-retrieval/pipeline/multi-query.test.ts +56 -0
- package/ee/agentic-retrieval/pipeline/multi-query.ts +14 -0
- package/ee/agentic-retrieval/pipeline/search.test.ts +21 -0
- package/ee/agentic-retrieval/pipeline/search.ts +8 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// ee/agentic-retrieval/pipeline/index.test.ts
|
|
2
2
|
import { createAgenticRetrievalTool, parsePreselectedItems } from "./index";
|
|
3
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
3
4
|
|
|
4
5
|
jest.mock("@EE/entitlements", () => ({ checkLicense: () => ({ "agentic-retrieval": true }) }));
|
|
5
6
|
jest.mock("@SRC/exulu/resolve-reranker", () => ({ resolveReranker: jest.fn(async () => ({ model: "m", rerank: async (_q: any, c: any) => c })) }));
|
|
@@ -392,3 +393,49 @@ describe("engine v2 — identifier pins run alongside memory and routing", () =>
|
|
|
392
393
|
expect(runMemoryPhase.mock.calls[0][0].mergedCall).toBeFalsy();
|
|
393
394
|
});
|
|
394
395
|
});
|
|
396
|
+
|
|
397
|
+
describe("a refused json filter path reaching the pipeline boundary", () => {
|
|
398
|
+
// --- Final review, Important 4 -----------------------------------------
|
|
399
|
+
//
|
|
400
|
+
// Spec Part C: a refused filter must come back as a normal tool RESULT
|
|
401
|
+
// carrying the message, not as a thrown error -- a bad filter is a typo
|
|
402
|
+
// the model fixes on its next call, not a turn-ending condition. This
|
|
403
|
+
// boundary's catch-all was reporting it as "Retrieval degraded due to an
|
|
404
|
+
// internal error -- returning partial results", so the model got partial
|
|
405
|
+
// results and no path list: Part C's exact target failure in new wording.
|
|
406
|
+
it("surfaces the refusal as the step text, not as the generic degraded message", async () => {
|
|
407
|
+
const { searchContexts } = jest.requireMock("./search");
|
|
408
|
+
searchContexts.mockRejectedValueOnce(
|
|
409
|
+
new UnknownFilterPathError("felder", ["konfidenz"], ["<key>.wert", "<key>.konfidenz"]),
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
const run = makeTool({});
|
|
413
|
+
const out = await drain(run(inputs));
|
|
414
|
+
// The tool result is the serialized output, so assert on the parsed
|
|
415
|
+
// step text rather than on the JSON-escaped string.
|
|
416
|
+
const payload = JSON.parse(out[out.length - 1].result as string);
|
|
417
|
+
const texts = (payload.steps as { text: string }[]).map((step) => step.text);
|
|
418
|
+
|
|
419
|
+
// The four-part refusal reaches the model verbatim, list of valid paths
|
|
420
|
+
// included -- that list is the whole point of Part C.
|
|
421
|
+
expect(texts).toContainEqual(expect.stringContaining('Filter on field "felder" rejected'));
|
|
422
|
+
expect(texts).toContainEqual(expect.stringContaining("<key>.konfidenz"));
|
|
423
|
+
expect(texts).not.toContainEqual(
|
|
424
|
+
expect.stringContaining("Retrieval degraded due to an internal error"),
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("every OTHER pipeline failure still reports the generic degraded message", async () => {
|
|
429
|
+
const { searchContexts } = jest.requireMock("./search");
|
|
430
|
+
searchContexts.mockRejectedValueOnce(new Error("connection reset"));
|
|
431
|
+
|
|
432
|
+
const run = makeTool({});
|
|
433
|
+
const out = await drain(run(inputs));
|
|
434
|
+
const payload = JSON.parse(out[out.length - 1].result as string);
|
|
435
|
+
const texts = (payload.steps as { text: string }[]).map((step) => step.text);
|
|
436
|
+
|
|
437
|
+
expect(texts).toContainEqual(
|
|
438
|
+
expect.stringContaining("Retrieval degraded due to an internal error"),
|
|
439
|
+
);
|
|
440
|
+
});
|
|
441
|
+
});
|
|
@@ -21,6 +21,7 @@ import { needsPinRerun } from "./pin-rerun";
|
|
|
21
21
|
import type { VectorSearchChunkResult } from "@SRC/graphql/resolvers/vector-search";
|
|
22
22
|
import { parsePreselectedItems } from "./global-ids";
|
|
23
23
|
import { isExternalOrAnonymousUser } from "@SRC/exulu/resolve-max-steps";
|
|
24
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
24
25
|
export { parsePreselectedItems } from "./global-ids";
|
|
25
26
|
|
|
26
27
|
// ---------------------------------------------------------------------------
|
|
@@ -803,6 +804,33 @@ export function createAgenticRetrievalTool(opts: {
|
|
|
803
804
|
yield { result: serializeOutput(result, hideSources) };
|
|
804
805
|
return { result: serializeOutput(result, hideSources) };
|
|
805
806
|
} catch (err) {
|
|
807
|
+
// A refused json filter path is the one failure here that is the
|
|
808
|
+
// CALLER's to fix, and the one that must never be reported as a
|
|
809
|
+
// degraded search (final review, Important 4). Spec Part C is
|
|
810
|
+
// explicit that a refused filter comes back as a normal tool
|
|
811
|
+
// RESULT carrying the message, not as a thrown error: a bad filter
|
|
812
|
+
// is a typo the model corrects on its next call, not a turn-ending
|
|
813
|
+
// condition. Reported as "Retrieval degraded due to an internal
|
|
814
|
+
// error — returning partial results", it was Part C's exact target
|
|
815
|
+
// failure in new wording — the model got partial results, no path
|
|
816
|
+
// list, and no reason to retry. `err.message` is already the
|
|
817
|
+
// complete four-part refusal (what was rejected, why, what was
|
|
818
|
+
// expected, and the full list of paths the schema DOES define), so
|
|
819
|
+
// it is surfaced verbatim as the step text. The throw itself stays
|
|
820
|
+
// where it is, deliberately (see UnknownFilterPathError's own doc
|
|
821
|
+
// comment); this is the boundary mapping that was missing.
|
|
822
|
+
if (err instanceof UnknownFilterPathError) {
|
|
823
|
+
console.warn("[EXULU pipeline] retrieval refused an unknown json filter path:", err.message);
|
|
824
|
+
result.steps.push({
|
|
825
|
+
stepNumber: 1,
|
|
826
|
+
text: err.message,
|
|
827
|
+
toolCalls: [],
|
|
828
|
+
chunks: [],
|
|
829
|
+
tokens: 0,
|
|
830
|
+
});
|
|
831
|
+
yield { result: serializeOutput(result, hideSources) };
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
806
834
|
console.warn("[EXULU pipeline] retrieval pipeline failed:", err);
|
|
807
835
|
result.steps.push({
|
|
808
836
|
stepNumber: 1,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { multiQuerySearch, singleSearch } from "./multi-query";
|
|
2
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
2
3
|
|
|
3
4
|
const chunk = (id: string, score = 1) => ({
|
|
4
5
|
chunk_id: id,
|
|
@@ -49,3 +50,58 @@ describe("multiQuerySearch", () => {
|
|
|
49
50
|
expect(ctx.search.mock.calls[0][0].itemFilters).toEqual([{ id: { in: ["x"] } }]);
|
|
50
51
|
});
|
|
51
52
|
});
|
|
53
|
+
|
|
54
|
+
// Final review, Important 4: singleSearch's catch-all turns any failure into
|
|
55
|
+
// zero chunks, which is right for a search that broke and wrong for a filter
|
|
56
|
+
// that cannot be answered -- an undeclared json filter path degraded to an
|
|
57
|
+
// empty result the model reports as "there are none", the exact silence spec
|
|
58
|
+
// Part C exists to end. It is re-thrown so the pipeline's boundary can
|
|
59
|
+
// surface the refusal message instead.
|
|
60
|
+
describe("singleSearch and a refused json filter path", () => {
|
|
61
|
+
it("re-throws UnknownFilterPathError instead of degrading it to zero chunks", async () => {
|
|
62
|
+
const err = new UnknownFilterPathError("felder", ["konfidenz"], ["<key>.konfidenz"]);
|
|
63
|
+
const ctx = { search: jest.fn().mockRejectedValue(err) };
|
|
64
|
+
|
|
65
|
+
await expect(
|
|
66
|
+
singleSearch({
|
|
67
|
+
query: "q",
|
|
68
|
+
config: { method: "hybridSearch", limit: 5 },
|
|
69
|
+
user: {},
|
|
70
|
+
role: "r",
|
|
71
|
+
pinnedItemIds: [],
|
|
72
|
+
context: ctx,
|
|
73
|
+
}),
|
|
74
|
+
).rejects.toBe(err);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("every OTHER failure is still swallowed into an empty result, exactly as before", async () => {
|
|
78
|
+
const ctx = { search: jest.fn().mockRejectedValue(new Error("connection reset")) };
|
|
79
|
+
|
|
80
|
+
await expect(
|
|
81
|
+
singleSearch({
|
|
82
|
+
query: "q",
|
|
83
|
+
config: { method: "hybridSearch", limit: 5 },
|
|
84
|
+
user: {},
|
|
85
|
+
role: "r",
|
|
86
|
+
pinnedItemIds: [],
|
|
87
|
+
context: ctx,
|
|
88
|
+
}),
|
|
89
|
+
).resolves.toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("multiQuerySearch propagates it too -- one refused filter is refused for every query variation", async () => {
|
|
93
|
+
const err = new UnknownFilterPathError("felder", ["konfidenz"], ["<key>.konfidenz"]);
|
|
94
|
+
const ctx = { search: jest.fn().mockRejectedValue(err) };
|
|
95
|
+
|
|
96
|
+
await expect(
|
|
97
|
+
multiQuerySearch({
|
|
98
|
+
queries: ["q1", "q2"],
|
|
99
|
+
config: { method: "hybridSearch", limit: 5 },
|
|
100
|
+
user: {},
|
|
101
|
+
role: "r",
|
|
102
|
+
pinnedItemIds: [],
|
|
103
|
+
context: ctx,
|
|
104
|
+
}),
|
|
105
|
+
).rejects.toBe(err);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
1
2
|
import { RRF_K } from "./config";
|
|
2
3
|
import type { Chunk } from "./types";
|
|
3
4
|
|
|
@@ -13,6 +14,18 @@ export type SearchCallConfig = {
|
|
|
13
14
|
/**
|
|
14
15
|
* Performs a single search with the given query and configuration.
|
|
15
16
|
* Wraps the context.search call in try/catch to handle failures gracefully.
|
|
17
|
+
*
|
|
18
|
+
* One exception is deliberately NOT handled gracefully (final review,
|
|
19
|
+
* Important 4): a refused json filter path (`UnknownFilterPathError`) is
|
|
20
|
+
* not a search that failed, it is a filter that cannot be answered — the
|
|
21
|
+
* caller asked about a path the field's declared schema does not define,
|
|
22
|
+
* and degrading that to zero chunks reproduces the exact silence spec Part
|
|
23
|
+
* C exists to end (an empty result the model reports as "there are none").
|
|
24
|
+
* It is re-thrown so it reaches the pipeline's own boundary
|
|
25
|
+
* (`pipeline/index.ts`), which turns it into a step the model can read and
|
|
26
|
+
* act on. `pipeline/search.ts`'s per-context catch re-throws it for the
|
|
27
|
+
* same reason — every swallow point between the query and that boundary
|
|
28
|
+
* has to pass it along, or the mapping exists and never fires.
|
|
16
29
|
*/
|
|
17
30
|
export async function singleSearch({
|
|
18
31
|
query,
|
|
@@ -53,6 +66,7 @@ export async function singleSearch({
|
|
|
53
66
|
|
|
54
67
|
return results.chunks || [];
|
|
55
68
|
} catch (e) {
|
|
69
|
+
if (e instanceof UnknownFilterPathError) throw e;
|
|
56
70
|
console.warn("[EXULU] singleSearch failed for query:", query, e);
|
|
57
71
|
return [];
|
|
58
72
|
}
|
|
@@ -7,6 +7,7 @@ jest.mock("./prefilter", () => ({ fuzzyPrefilter: jest.fn(async () => [{ id: "p1
|
|
|
7
7
|
import { multiQuerySearch, singleSearch } from "./multi-query";
|
|
8
8
|
import { generateHydePassage } from "./hyde";
|
|
9
9
|
import { fuzzyPrefilter } from "./prefilter";
|
|
10
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
10
11
|
|
|
11
12
|
const contextsById = new Map<string, any>([
|
|
12
13
|
["docs", { id: "docs", configuration: {} }],
|
|
@@ -189,3 +190,23 @@ describe("searchContexts", () => {
|
|
|
189
190
|
expect((multiQuerySearch as jest.Mock).mock.calls[0][0].pinnedItemIds).toEqual(["s1"]);
|
|
190
191
|
});
|
|
191
192
|
});
|
|
193
|
+
|
|
194
|
+
// Final review, Important 4: the second swallow point between the query and
|
|
195
|
+
// the pipeline's boundary. Its per-context catch returns [] so one broken
|
|
196
|
+
// context cannot take the whole retrieval down -- correct for a failed
|
|
197
|
+
// search, wrong for a filter path no schema defines, which is wrong for
|
|
198
|
+
// every context and has a message the model can act on.
|
|
199
|
+
describe("searchContexts and a refused json filter path", () => {
|
|
200
|
+
it("re-throws UnknownFilterPathError instead of degrading that context to zero chunks", async () => {
|
|
201
|
+
const err = new UnknownFilterPathError("felder", ["konfidenz"], ["<key>.konfidenz"]);
|
|
202
|
+
(multiQuerySearch as jest.Mock).mockRejectedValueOnce(err);
|
|
203
|
+
|
|
204
|
+
await expect(searchContexts({ ...base, contextIds: ["docs"] })).rejects.toBe(err);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("every OTHER per-context failure is still swallowed, exactly as before", async () => {
|
|
208
|
+
(multiQuerySearch as jest.Mock).mockRejectedValueOnce(new Error("connection reset"));
|
|
209
|
+
|
|
210
|
+
await expect(searchContexts({ ...base, contextIds: ["docs"] })).resolves.toEqual({ chunks: [] });
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -6,6 +6,7 @@ import { withTiming } from "./timing";
|
|
|
6
6
|
import { applyRewrites } from "./text-utils";
|
|
7
7
|
import type { Chunk } from "./types";
|
|
8
8
|
import { isEmbedderNotConfigured } from "@SRC/exulu/embedder-not-configured";
|
|
9
|
+
import { UnknownFilterPathError } from "@SRC/graphql/utilities/convert-graphql-filter-operator-to-pg-query";
|
|
9
10
|
|
|
10
11
|
/** Attach the source knowledge base to each chunk so citations and the chat UI can
|
|
11
12
|
* attribute passages deterministically. Only memory chunks were labeled before; the
|
|
@@ -185,6 +186,13 @@ export async function searchContexts(opts: {
|
|
|
185
186
|
|
|
186
187
|
return [];
|
|
187
188
|
} catch (err) {
|
|
189
|
+
// A refused json filter path is not "this context failed to search"
|
|
190
|
+
// (final review, Important 4): the filter names a path no schema
|
|
191
|
+
// defines, so it is wrong for every context, and returning [] here
|
|
192
|
+
// would hand the model an empty result instead of the refusal that
|
|
193
|
+
// tells it what to fix. Re-thrown so `pipeline/index.ts`'s own
|
|
194
|
+
// boundary can surface the message as a step.
|
|
195
|
+
if (err instanceof UnknownFilterPathError) throw err;
|
|
188
196
|
if (isEmbedderNotConfigured(err)) {
|
|
189
197
|
console.warn(
|
|
190
198
|
`[EXULU pipeline] context "${ctxId}" is not searchable: ${(err as Error).message}`,
|