|
| 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. |
0 commit comments