mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
fix(knowledge-fs): handle unknown unit ID errors with LlmSemanticChunkingOutputError
This commit is contained in:
parent
f291a76135
commit
b904fbe066
@ -13,6 +13,7 @@ import { createInMemoryDocumentSemanticWindowCheckpointRepository } from "./docu
|
||||
|
||||
import {
|
||||
DEFAULT_MAX_SEMANTIC_WINDOWS,
|
||||
LlmSemanticChunkingOutputError,
|
||||
type LlmSemanticCompletionCatalogEntry,
|
||||
type LlmSemanticWindowManifestEntry,
|
||||
type SemanticChunkingLlmProvider,
|
||||
@ -1513,6 +1514,36 @@ describe("LLM semantic chunker", () => {
|
||||
).rejects.toThrow(error);
|
||||
});
|
||||
|
||||
it("classifies an unknown response unit ID as an invalid model-runtime response", async () => {
|
||||
const chunker = createLlmSemanticChunker({
|
||||
maxChunkChars: 20,
|
||||
reasoningProviderFactory: () =>
|
||||
new ScriptedProvider([
|
||||
({ units }) => ({ chunks: [chunkRange(units[0]?.id, "u-missing")] }),
|
||||
]),
|
||||
});
|
||||
|
||||
const failure = chunker.chunk({
|
||||
knowledgeSpaceId: KNOWLEDGE_SPACE_ID,
|
||||
parseArtifact: artifact([
|
||||
{
|
||||
id: "paragraph",
|
||||
metadata: {},
|
||||
sectionPath: ["Validation"],
|
||||
text: "Alpha. Beta.",
|
||||
type: "paragraph",
|
||||
},
|
||||
]),
|
||||
retrievalProfile: profile(),
|
||||
});
|
||||
|
||||
await expect(failure).rejects.toBeInstanceOf(LlmSemanticChunkingOutputError);
|
||||
await expect(failure).rejects.toMatchObject({
|
||||
code: "MODEL_RUNTIME_RESPONSE_INVALID",
|
||||
retryable: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("drops ungrounded image OCR entities and their relations without discarding the chunk", async () => {
|
||||
const provider = new ScriptedProvider([
|
||||
({ units }) => ({
|
||||
|
||||
@ -2836,7 +2836,9 @@ function validateAndMaterializeWindowOutput({
|
||||
const start = unitIndex.get(candidate.startUnitId);
|
||||
const end = unitIndex.get(candidate.endUnitId);
|
||||
if (start === undefined || end === undefined) {
|
||||
throw new Error("LLM semantic chunking response referenced an unknown unit ID");
|
||||
throw new LlmSemanticChunkingOutputError(
|
||||
"LLM semantic chunking response referenced an unknown unit ID",
|
||||
);
|
||||
}
|
||||
if (start !== expectedStart || end < start) {
|
||||
throw new Error(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user