feat: D16 adjudication — 2v2 stays hypothesis until a rule fires. (#35)
Tests / Test (push) Skipped
Tests / OCR (tesseract fixture) (push) Skipped
Tests / Release (semver) (push) Skipped
Tests / Test (push) Skipped
Tests / OCR (tesseract fixture) (push) Skipped
Tests / Release (semver) (push) Skipped
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")
|
||||
}
|
||||
}
|
||||
|
||||
+22
-13
@@ -212,7 +212,11 @@ func rowsToHits(res *lbug.QueryResult) ([]Hit, error) {
|
||||
root := fmt.Sprint(vals[2])
|
||||
source := fmt.Sprint(vals[3])
|
||||
score := float64(vals[4].(float64))
|
||||
hits = append(hits, Hit{ID: id, Text: text, Root: root, Source: source, Score: score})
|
||||
conf := ""
|
||||
if len(vals) >= 6 {
|
||||
conf = fmt.Sprint(vals[5])
|
||||
}
|
||||
hits = append(hits, Hit{ID: id, Text: text, Root: root, Source: source, Score: score, Confidence: conf})
|
||||
}
|
||||
return hits, nil
|
||||
}
|
||||
@@ -227,24 +231,26 @@ type jsonOut struct {
|
||||
}
|
||||
|
||||
type jsonHit struct {
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Root string `json:"root"`
|
||||
Score float64 `json:"score"`
|
||||
Snippet string `json:"snippet,omitempty"`
|
||||
Hops []rank.HopNode `json:"hops,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Text string `json:"text"`
|
||||
Root string `json:"root"`
|
||||
Confidence string `json:"confidence,omitempty"`
|
||||
Score float64 `json:"score"`
|
||||
Snippet string `json:"snippet,omitempty"`
|
||||
Hops []rank.HopNode `json:"hops,omitempty"`
|
||||
}
|
||||
|
||||
func toJSONOut(hits []Hit, query, rootFilter string, web *rank.SecondSource) *jsonOut {
|
||||
out := make([]jsonHit, len(hits))
|
||||
for i, h := range hits {
|
||||
out[i] = jsonHit{
|
||||
ID: h.ID,
|
||||
Text: h.Text,
|
||||
Root: h.Root,
|
||||
Score: h.Score,
|
||||
Snippet: h.Snippet,
|
||||
Hops: h.Hops,
|
||||
ID: h.ID,
|
||||
Text: h.Text,
|
||||
Root: h.Root,
|
||||
Confidence: h.Confidence,
|
||||
Score: h.Score,
|
||||
Snippet: h.Snippet,
|
||||
Hops: h.Hops,
|
||||
}
|
||||
}
|
||||
return &jsonOut{
|
||||
@@ -265,6 +271,9 @@ func resultsToDicts(hits []Hit) []any {
|
||||
{"root", h.Root},
|
||||
{"score", h.Score},
|
||||
}
|
||||
if h.Confidence != "" {
|
||||
d = append(d, KV{"confidence", h.Confidence})
|
||||
}
|
||||
if h.Snippet != "" {
|
||||
d = append(d, KV{"snippet", h.Snippet})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user