Complete source index reuse across extractors

This commit is contained in:
2026-11-26 01:41:33 +00:00
parent 553276c0a0
commit a27c2cd89c
17 changed files with 83 additions and 15 deletions

View File

@@ -72,7 +72,11 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
}
chunk := source.Chunk{ID: req.Chunk.ID, Ref: req.Chunk.Ref}
index := source.NewDocumentIndex(req.Source)
index := req.SourceIndex
if index == nil {
local := source.NewDocumentIndex(req.Source)
index = &local
}
reuse := func(value dnd.SceneDescriptionList) (dnd.SceneDescriptionList, error) {
if len(value.Scenes) != 1 || value.Scenes[0].SourceRef != chunk.Ref {
return dnd.SceneDescriptionList{}, fmt.Errorf("cached scene does not describe the current chunk range")
@@ -80,7 +84,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
// Chunk ordinals can change without changing the semantic prompt.
value.Scenes = append([]dnd.SceneDescription(nil), value.Scenes...)
value.Scenes[0].ID = chunk.ID
return sceneFallback(&value, chunk, index)
return sceneFallback(&value, chunk, *index)
}
materials := shared.PromptInputs(sourceInput, req.References)
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
@@ -103,7 +107,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
if evaluation != nil {
final = evaluation.View().Candidate
}
return sceneFallback(final, chunk, index)
return sceneFallback(final, chunk, *index)
}}, nil
}