Reuse source indexes in occurrence extraction
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
@@ -92,12 +93,17 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
if !registry.Bound() {
|
||||
return nil, extractorErrorf("location registry reference is required")
|
||||
}
|
||||
grounding, err := locationregistry.NewGrounding(registry, req.Source)
|
||||
index := req.SourceIndex
|
||||
if index == nil {
|
||||
local := source.NewDocumentIndex(req.Source)
|
||||
index = &local
|
||||
}
|
||||
grounding, err := locationregistry.NewGroundingForSource(registry, req.Source, index)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare location grounding: %w", err)
|
||||
}
|
||||
|
||||
order := shared.NewSourceRefOrder(req.Source)
|
||||
order := shared.NewSourceRefOrderForSource(req.Source, index)
|
||||
|
||||
sourceID := req.Source.ID
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
|
||||
@@ -31,6 +31,8 @@ func TestExtractMapsKindsOrdersOccurrencesAndPreservesIndependentFacts(t *testin
|
||||
references := registryReferences(t, locations)
|
||||
req := extractionRequest()
|
||||
req.References = references
|
||||
index := source.NewDocumentIndex(req.Source)
|
||||
req.SourceIndex = &index
|
||||
result, err := runExtraction(context.Background(), newExtractor(t, client, references), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -48,6 +48,7 @@ func occurrenceRefs(start, end int) []occurrenceSourceRefResponse {
|
||||
|
||||
type extractionTestInput struct {
|
||||
Source *source.SourceDocument
|
||||
SourceIndex *source.DocumentIndex
|
||||
Chunk *source.Chunk
|
||||
AmbientContext map[string]any
|
||||
SourceInput contracts.LLMInputMaterial
|
||||
@@ -102,7 +103,7 @@ func runExtraction(ctx context.Context, fixture *extractionFixture, req extracti
|
||||
}
|
||||
op := req.Execution
|
||||
execution := pipeline.ExecutionContext[dnd.LocationOccurrenceList]{Engine: engine, Controls: op.Controls, Assess: op.Assess, Execution: op.Execution, ReuseEligible: op.ReuseEligible, Cache: op.Cache}
|
||||
input := contracts.ExtractionInput{Source: req.Source, Chunk: req.Chunk, SourceInput: req.SourceInput, SessionID: req.SessionID, References: req.References, LLMProfile: req.LLMProfile, Metadata: req.Metadata, AmbientContext: req.AmbientContext}
|
||||
input := contracts.ExtractionInput{Source: req.Source, SourceIndex: req.SourceIndex, Chunk: req.Chunk, SourceInput: req.SourceInput, SessionID: req.SessionID, References: req.References, LLMProfile: req.LLMProfile, Metadata: req.Metadata, AmbientContext: req.AmbientContext}
|
||||
return pipeline.ExecuteOperation(ctx, execution, func(ctx context.Context) (contracts.PreparedOperation[dnd.LocationOccurrenceList], error) {
|
||||
return extractor.PrepareExtraction(ctx, input)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user