Skip to content

Latest commit

 

History

History
277 lines (209 loc) · 13.7 KB

ENHANCED_RETRIEVAL_REPORT.md

File metadata and controls

277 lines (209 loc) · 13.7 KB

CEMS Enhanced Retrieval System - Comprehensive Report

Executive Summary

The enhanced retrieval system shows significant improvements in finding semantically relevant memories:

Metric Raw Search Enhanced Search Improvement
Datecs query top score 0.46 0.80 +73%
Python prefs top score 0.26 0.61 +135%
Debugging query top score 0.29 0.61 +110%

Key finding: The enhanced system successfully finds memories about "datecs.ro" when searching for "datecs fp-700 printer" - even though the stored memory doesn't contain "fp-700".


LLM Prompts Used in Pipeline

1. Query Synthesis Prompt

Purpose: Expand user query into multiple search terms for better coverage

Generate 2-3 search queries to find memories about the EXACT SAME TOPIC.

User query: {query}

CRITICAL RULES:
- Stay within the SAME specific domain/topic
- NO generalizing to broader categories
- Prefer specific technical terms over generic words
- Only add synonyms for the exact topic, not related areas

Return one search term per line. No bullets, no numbering.

Example output for "datecs fp-700 printer":

  • "datecs fp-700 printer remote access ERPNet Windows"
  • "Windows ERPNet connection Datecs FP-700 printer"
  • "remote connection Datecs FP-700 printer ERPNet Windows"

2. HyDE (Hypothetical Document Embeddings) Prompt

Purpose: Generate what an ideal memory would look like to improve vector matching

You are a memory retrieval system. Given this query, generate a 
hypothetical memory entry (2-3 sentences) that would perfectly answer it.

Query: {query}

Write the memory AS IF it was stored previously by a developer. Be specific and concrete.
Include relevant technical details, file paths, commands, or preferences that would help.

Hypothetical memory:

Example output for "datecs fp-700 printer Windows remote connection":

"To establish a Windows remote connection to the Datecs FP-700 printer, ensure you have the latest drivers installed from the Datecs website. Configure the printer by navigating to Control Panel > Devices and Printers..."


3. LLM Re-ranking Prompt

Purpose: Use LLM to evaluate actual relevance, not just similarity

Given this search query, rank these memory candidates by ACTUAL RELEVANCE.

Query: {query}

Candidates:
{numbered list of candidates with category and content preview}

IMPORTANT: Only include memories that are ACTUALLY relevant to the query.
A memory about SSH to Hetzner is NOT relevant to a query about Windows printers.
A memory about SEO scripts is NOT relevant to a query about fiscal printers.

Return a JSON array of indices (1-based) in relevance order.
Only include indices of memories that are TRULY relevant.
If nothing is relevant, return an empty array [].

Example: [3, 1, 7] means candidate 3 is most relevant, then 1, then 7.

JSON array:

Key feature: Explicitly instructs to filter out semantically unrelated results (SSH, SEO scripts).


4. Query Intent Analysis Prompt

Purpose: Smart routing based on query complexity

Analyze this memory search query and extract its intent.

Query: {query}

Return JSON with:
{
  "primary_intent": "<troubleshooting|how-to|factual|recall|preference>",
  "complexity": "<simple|moderate|complex>",
  "domains": ["<domain1>", "<domain2>"],
  "entities": ["<entity1>", "<entity2>"],
  "requires_reasoning": <true|false>
}

Routing logic:

  • Simple queries → fast vector path
  • Complex queries → full hybrid (HyDE + RRF + reranking)

5. Category Summary Matching Prompt (NEW)

Purpose: Use category summaries to boost relevant categories

Given this search query, which categories are most relevant?

Query: {query}

Available categories:
{list of categories with summary previews}

Return a JSON object with category names as keys and relevance scores (0.0-1.0) as values.
Only include categories with relevance >= 0.3.
Example: {"debugging": 0.9, "deployment": 0.5}

JSON:

Pipeline Stages (9-Stage Enhanced Pipeline)

┌─────────────────────────────────────────────────────────────────┐
│  QUERY: "datecs fp-700 printer Windows remote connection"       │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 1: Query Understanding                                   │
│  → Intent: how-to, Complexity: complex, Domains: [printers]     │
│  → Route to: HYBRID mode                                        │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 2: Query Synthesis (LLM)                                 │
│  → Original + 3 expanded queries = 4 queries                    │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 3: HyDE Generation (LLM)                                 │
│  → Generate hypothetical ideal memory                           │
│  → Add as 5th search query                                      │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 4: Candidate Retrieval                                   │
│  → Vector search: 20 results per query × 5 = 100 results        │
│  → Graph traversal: 5 related memories                          │
│  → Total: 105 candidates                                        │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 5: RRF Fusion                                            │
│  → Combine 105 candidates → 26 unique (deduplicated)            │
│  → Score = 60% RRF rank + 40% original vector score             │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 6: LLM Re-ranking                                        │
│  → LLM evaluates top 20 candidates                              │
│  → Filters out irrelevant (SSH, SEO, etc.)                      │
│  → Returns 7 truly relevant                                     │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 7: Relevance Filtering                                   │
│  → Threshold: 0.4 minimum score                                 │
│  → 7 → 2 candidates pass                                        │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 8: Scoring Adjustments                                   │
│  → Time decay: 50% per month                                    │
│  → Priority boost: up to 2x for hot memories                    │
│  → Pinned boost: +10%                                           │
│  → Category boost: from summary matching                        │
│  → Project boost: +30% same project, -20% different             │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│  STAGE 9: Token-Budgeted Assembly                               │
│  → Select results within 2000 token budget                      │
│  → Final: 2 results, 44 tokens                                  │
└─────────────────────────────────────────────────────────────────┘

Test Results: Complex Memory Retrieval

Test Setup

Added 10 memories designed to have NO keyword overlap with their target queries:

Memory Target Query Keyword Overlap Result
"datecs.ro diagnostic tool" "datecs fp-700 printer" datecs (partial) ✅ Found
"ENQ->ACK->STX handshake" "erpnet fp fiscal printer" fiscal (partial) ✅ Found
"WinRM PowerShell sessions" "remote Windows script" Windows ✅ Found
"type hints, dataclasses, f-strings" "Python preferences" NONE ✅ Found
"check logs, print statements" "find bugs in code" NONE ✅ Found

Key Observations

  1. HyDE dramatically improves recall: By generating hypothetical documents, the system finds memories that share concepts but not keywords.

  2. LLM reranking filters irrelevant results: The "SSH to Hetzner" memory was correctly NOT returned when searching for "datecs printer".

  3. Graph traversal adds related memories: When searching for Kubernetes, Docker-related memories were found via entity relationships.

  4. Category summaries provide context boost: Memories from relevant categories get higher scores.


Active Features Status

Feature Status Impact
Project Filtering ✅ Active +30%/-20% boost/penalty
Time Decay ✅ Active 50% per month
Priority Boost ✅ Active Up to 2x for hot memories
Query Synthesis ✅ Active 2-3 expanded queries
HyDE ✅ Active Hypothetical document generation
RRF Fusion ✅ Active Combines multi-query results
LLM Re-ranking ✅ Active Filters irrelevant results
Graph Traversal ✅ Active RELATES_TO edges + entity links
Category Summaries ✅ Active (NEW) Boosts relevant categories
Short-term Memory ⚠️ Partial Time decay exists, TTL not enforced

Recommendations

  1. Monitor LLM costs: The enhanced pipeline makes 3-4 LLM calls per query. Consider Groq API for faster/cheaper inference.

  2. Tune relevance threshold: Current 0.4 threshold may be too aggressive. Consider 0.3 for better recall.

  3. Add TTL enforcement: The expires_at field exists but isn't enforced. Add to search filters for true short-term memory.

  4. Build more graph edges: Consider a nightly job to compute similarity between all memories and create RELATES_TO edges.


Files Modified

  • src/cems/retrieval.py - Added HyDE, RRF, LLM reranking, query understanding
  • src/cems/memory.py - Enhanced pipeline, category summary integration
  • src/cems/graph.py - RELATES_TO edge creation in process_memory()
  • src/cems/server.py - Mode parameter, intent in response
  • test_complex_memories.py - Comprehensive semantic test suite
  • docker-compose.yml - Added port mapping for testing

Report generated: January 26, 2026