feat: D16 adjudication — 2v2 stays hypothesis until a rule fires.
temporal_freshness then authority_pairing; unresolved keeps (not confirmed). bin/facts/audit contradict. Gitea #29.
This commit is contained in:
@@ -19,20 +19,35 @@ type SecondSourceHit struct {
|
||||
|
||||
type WebFn func(query string) SecondSource
|
||||
|
||||
// ShouldEscalate is true when the default deduction path has no facts hit.
|
||||
// ShouldEscalate is true when the default deduction path has no confirmed
|
||||
// facts hit. Hypothesis/partial facts are `(not confirmed)` (D16).
|
||||
// `--root facts|info` is a single-root ask: do not mix in the web.
|
||||
func ShouldEscalate(hits []Hit, rootFilter string) bool {
|
||||
if rootFilter != "" {
|
||||
return false
|
||||
}
|
||||
for _, h := range hits {
|
||||
if h.Root == "facts" {
|
||||
if ConfirmedFact(h) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ConfirmedFact is a facts-root hit that is not hypothesis/partial.
|
||||
// Empty confidence is treated as confirmed (legacy leafs).
|
||||
func ConfirmedFact(h Hit) bool {
|
||||
if h.Root != "facts" {
|
||||
return false
|
||||
}
|
||||
switch h.Confidence {
|
||||
case "hypothesis", "partial":
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Deduce returns the second-source block, or nil when web must not run.
|
||||
func Deduce(hits []Hit, query, rootFilter string, noWeb bool, web WebFn) *SecondSource {
|
||||
if noWeb || web == nil || !ShouldEscalate(hits, rootFilter) {
|
||||
|
||||
@@ -14,6 +14,16 @@ func TestShouldEscalateWhenNoFacts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldEscalateWhenHypothesisFacts(t *testing.T) {
|
||||
hyp := Hit{ID: "c", Root: "facts", Confidence: "hypothesis", Source: "a x b vs c x d"}
|
||||
if !ShouldEscalate([]Hit{hyp}, "") {
|
||||
t.Fatal("hypothesis facts are (not confirmed); escalate")
|
||||
}
|
||||
if ConfirmedFact(hyp) {
|
||||
t.Fatal("hypothesis is not confirmed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldNotEscalateWhenFactsConfirm(t *testing.T) {
|
||||
hits := []Hit{h("f", "facts", "docker ps x compose"), h("i", "info", "docs/a.md")}
|
||||
if ShouldEscalate(hits, "") {
|
||||
|
||||
@@ -3,10 +3,10 @@ package rank
|
||||
// BM25 ranks best-first, so the top hits are the *highest* scores; cosine
|
||||
// distance ranks best-first ascending. Both mirror kblib.py.
|
||||
const FTSStmt = "CALL QUERY_FTS_INDEX('Leaf', 'id', $q) " +
|
||||
"RETURN node.id, node.text, node.root, node.source, score ORDER BY score DESC LIMIT $n"
|
||||
"RETURN node.id, node.text, node.root, node.source, score, node.confidence ORDER BY score DESC LIMIT $n"
|
||||
|
||||
const VecStmt = "CALL QUERY_VECTOR_INDEX('Leaf', 'Leaf_vec', $q, $n) " +
|
||||
"RETURN node.id, node.text, node.root, node.source, distance ORDER BY distance LIMIT $n"
|
||||
"RETURN node.id, node.text, node.root, node.source, distance, node.confidence ORDER BY distance LIMIT $n"
|
||||
|
||||
// HopStmt is the Cypher walk from a search hit. Depth 1 = File, 2 = Commit, 3 = Person.
|
||||
func HopStmt(depth int) string {
|
||||
|
||||
@@ -16,13 +16,14 @@ type HopNode struct {
|
||||
|
||||
// Hit is one search result, mirroring the python script's dict shape.
|
||||
type Hit struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Root string `json:"root"`
|
||||
Source string `json:"-"`
|
||||
Score float64 `json:"score"`
|
||||
Snippet string `json:"snippet,omitempty"`
|
||||
Hops []HopNode `json:"hops,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Root string `json:"root"`
|
||||
Confidence string `json:"confidence,omitempty"`
|
||||
Source string `json:"-"`
|
||||
Score float64 `json:"score"`
|
||||
Snippet string `json:"snippet,omitempty"`
|
||||
Hops []HopNode `json:"hops,omitempty"`
|
||||
}
|
||||
|
||||
// rrfK dampens the contribution of low ranks; same constant as kblib.py.
|
||||
|
||||
@@ -172,4 +172,7 @@ func TestFTSQueryOrdersByScoreDescending(t *testing.T) {
|
||||
if !strings.Contains(FTSStmt, "ORDER BY score DESC") {
|
||||
t.Fatalf("FTS query must order by score DESC, got:\n%s", FTSStmt)
|
||||
}
|
||||
if !strings.Contains(FTSStmt, "node.confidence") {
|
||||
t.Fatal("FTS must return confidence for D16")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user