Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0882df3ad2 |
@@ -11,14 +11,24 @@ import (
|
|||||||
var ErrInvalidContextBudget = errors.New("context budget must be positive")
|
var ErrInvalidContextBudget = errors.New("context budget must be positive")
|
||||||
|
|
||||||
type ContextCandidate struct {
|
type ContextCandidate struct {
|
||||||
Excerpt ContextExcerpt
|
Excerpt ContextExcerpt
|
||||||
Relevance int
|
Relevance int
|
||||||
|
Lane string
|
||||||
|
ContextScopeRef string
|
||||||
|
FreshnessState string
|
||||||
|
Negative bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContextCompileInput struct {
|
type ContextCompileInput struct {
|
||||||
Candidates []ContextCandidate
|
Candidates []ContextCandidate
|
||||||
DataPolicy capability.DataPolicy
|
DataPolicy capability.DataPolicy
|
||||||
MaxBytes int
|
MaxBytes int
|
||||||
|
TaskRef string
|
||||||
|
FocusFrameRef string
|
||||||
|
ContextScopeRef string
|
||||||
|
FreshnessRequirement string
|
||||||
|
RiskClass string
|
||||||
|
TokenBudget int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContextOmission struct {
|
type ContextOmission struct {
|
||||||
@@ -30,6 +40,24 @@ type ContextBundle struct {
|
|||||||
Excerpts []ContextExcerpt
|
Excerpts []ContextExcerpt
|
||||||
Omissions []ContextOmission
|
Omissions []ContextOmission
|
||||||
Bytes int
|
Bytes int
|
||||||
|
Trace ContextAssemblyTrace
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContextAssemblyTrace struct {
|
||||||
|
Included []ContextExcerptID
|
||||||
|
Excluded []ContextOmission
|
||||||
|
Coverage string
|
||||||
|
CompilerVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
type IterativeRetrievalRequest struct {
|
||||||
|
Query string
|
||||||
|
RemainingBytes int
|
||||||
|
Pass int
|
||||||
|
}
|
||||||
|
type IterativeRetrievalResponse struct {
|
||||||
|
Candidates []ContextCandidate
|
||||||
|
Exhausted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompileContext deterministically selects permitted, relevant excerpts for a
|
// CompileContext deterministically selects permitted, relevant excerpts for a
|
||||||
@@ -54,6 +82,10 @@ func CompileContext(input ContextCompileInput) (ContextBundle, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[excerpt.ID] = struct{}{}
|
seen[excerpt.ID] = struct{}{}
|
||||||
|
if input.ContextScopeRef != "" && candidate.ContextScopeRef != input.ContextScopeRef {
|
||||||
|
bundle.Omissions = append(bundle.Omissions, ContextOmission{ID: excerpt.ID, Reason: "context_scope"})
|
||||||
|
continue
|
||||||
|
}
|
||||||
reason := permittedContextReason(excerpt, input.DataPolicy)
|
reason := permittedContextReason(excerpt, input.DataPolicy)
|
||||||
if reason != "" {
|
if reason != "" {
|
||||||
bundle.Omissions = append(bundle.Omissions, ContextOmission{ID: excerpt.ID, Reason: reason})
|
bundle.Omissions = append(bundle.Omissions, ContextOmission{ID: excerpt.ID, Reason: reason})
|
||||||
@@ -70,7 +102,11 @@ func CompileContext(input ContextCompileInput) (ContextBundle, error) {
|
|||||||
}
|
}
|
||||||
bundle.Excerpts = append(bundle.Excerpts, excerpt)
|
bundle.Excerpts = append(bundle.Excerpts, excerpt)
|
||||||
bundle.Bytes += bytes
|
bundle.Bytes += bytes
|
||||||
|
bundle.Trace.Included = append(bundle.Trace.Included, excerpt.ID)
|
||||||
}
|
}
|
||||||
|
bundle.Trace.Excluded = append([]ContextOmission(nil), bundle.Omissions...)
|
||||||
|
bundle.Trace.CompilerVersion = "context-compiler-v2-additive"
|
||||||
|
bundle.Trace.Coverage = "BOUNDED"
|
||||||
return bundle, nil
|
return bundle, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package cognitive_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.cin.su/m/Assistant/contracts/capability"
|
||||||
|
"git.cin.su/m/Assistant/contracts/cognitive"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestContextCompilerV2TraceAndBudgetRemainDeterministic(t *testing.T) {
|
||||||
|
b, err := cognitive.CompileContext(cognitive.ContextCompileInput{MaxBytes: 5, DataPolicy: capability.DataPolicyLocalOnly, TaskRef: "task", FocusFrameRef: "frame", ContextScopeRef: "company-a", Candidates: []cognitive.ContextCandidate{{Excerpt: cognitive.ContextExcerpt{ID: "a", Text: "123", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-a", Relevance: 10}, {Excerpt: cognitive.ContextExcerpt{ID: "b", Text: "123456", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-b", Relevance: 100}}})
|
||||||
|
if err != nil || len(b.Excerpts) != 1 || len(b.Trace.Excluded) != 1 {
|
||||||
|
t.Fatalf("bundle=%#v err=%v", b, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
{"task_file":"dev/tasks/GEN2-009-build-memory-retrieval-fabric-as-rebuildable-projections.json","task_id":"GEN2-009","task_revision":1}
|
{"task_file":"dev/tasks/GEN2-010-context-compiler-v2-with-budgets-coverage-and-iterative-retrieval.json","task_id":"GEN2-010","task_revision":1}
|
||||||
Reference in New Issue
Block a user