Skip to content

Commit 2bf8e2d

Browse files
docs: fix confidence scoring accuracy and default threshold (#132)
* docs: add confidence scoring explanation page * docs: fix confidence scoring doc accuracy and default threshold value --------- Co-authored-by: ahfoysal <ahfoysal30@gmail.com>
1 parent b18db12 commit 2bf8e2d

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

docs/wiki/Confidence-Scoring.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Confidence Scoring
2+
3+
CCE ranks every retrieved chunk with a confidence score before returning it.
4+
5+
## What the score combines
6+
7+
1. **Vector similarity score (50%)**
8+
- Uses cosine distance from the embedding query match.
9+
- The raw distance is normalized to `[0, 1]` by dividing by 2, then converted: `max(0, 1 - normalized_distance)`.
10+
11+
2. **Keyword/file-hint score (40%)**
12+
- Uses parser signal such as matched keywords and file hints.
13+
- A distance in `[0, 5]` is converted to a score: `max(0, 1 - keyword_distance / 5)`.
14+
15+
3. **Recency score (10%)**
16+
- Newer chunks get higher weight using exponential decay.
17+
- Missing `modified_ts` metadata defaults to a neutral score of `0.5`.
18+
- Half-life is one week.
19+
20+
## Formula
21+
22+
The confidence value is a weighted sum:
23+
24+
```python
25+
confidence = (0.5 * vector_score) + (0.4 * keyword_score) + (0.1 * recency_score)
26+
```
27+
28+
Clamped to `[0.0, 1.0]`.
29+
30+
## Final ranking stages
31+
32+
The confidence value is blended with the hybrid retriever signal (RRF) before filtering:
33+
34+
- Hybrid vector + full-text scores are merged first (RRF), then normalized to `[0, 1]`.
35+
- Each chunk gets a final score that is a 50/50 blend: `0.5 * confidence + 0.5 * normalized_rrf`.
36+
- Path penalties are applied (test files and docs are down-weighted by 20%).
37+
- Chunks below `confidence_threshold` are dropped.
38+
- Remaining chunks are sorted high-to-low by final score.
39+
40+
Note: `confidence_threshold` is compared against the blended final score, not the raw confidence value. A chunk with a strong RRF rank can pass the threshold even if its raw confidence score is modest.
41+
42+
A higher score means the chunk is considered more relevant and trustworthy for that query.
43+
44+
## `confidence_threshold`
45+
46+
Configured under `retrieval.confidence_threshold` in `~/.cce/config.yaml`:
47+
48+
- Lower values (for example `0.1`) return more results.
49+
- Higher values (for example `0.7`) return fewer but tighter matches.
50+
- Default is `0.2`.
51+
52+
```yaml
53+
retrieval:
54+
confidence_threshold: 0.2
55+
```
56+
57+
## Practical tuning
58+
59+
- If your queries feel too narrow, lower the threshold slightly (for example `0.1`).
60+
- If you want cleaner, fewer results, raise it (for example `0.5`).
61+
- The value is compared against the blended score (confidence + RRF), so it controls both relevance and retrieval rank.

docs/wiki/Configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ indexer:
3131

3232
retrieval:
3333
top_k: 20 # Maximum number of chunks to return per query
34-
confidence_threshold: 0.5 # Minimum confidence score to include a result (0.0–1.0)
34+
confidence_threshold: 0.2 # Minimum confidence score to include a result (0.0–1.0)
3535

3636
embedding:
3737
model: BAAI/bge-small-en-v1.5 # Embedding model (fastembed-compatible)
@@ -116,7 +116,7 @@ You do not need to set this manually — it is detected at startup.
116116

117117
**`top_k`** — how many chunks the retriever returns per query. Higher values surface more context but cost more tokens. Default: 20.
118118

119-
**`confidence_threshold`** — minimum score to include a result. Range 0.0 to 1.0. Lower values return more results; higher values return only strong matches. Default: 0.5.
119+
**`confidence_threshold`** — minimum score to include a result. Range 0.0 to 1.0. Lower values return more results; higher values return only strong matches. Default: 0.2.
120120

121121
At runtime, Claude can pass `top_k` and `max_tokens` directly to `context_search`:
122122
```

docs/wiki/How-It-Works.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ Every chunk gets a final confidence score combining:
8888

8989
Only chunks above the configured `confidence_threshold` (default 0.5) are returned.
9090

91+
For the exact formula and tuning notes, see [Confidence Scoring](Confidence-Scoring.md).
92+
9193
---
9294

9395
## 6. Compression

0 commit comments

Comments
 (0)