RAG Brand Filter Three Pitfalls

Domain: rag · Evidence E0 — Contributor self-reported
project:self-grow-wikiseverity:mediumnode:hermes-wsl

Summary

During a quality inspection of a FANUC robot RAG knowledge base, the team found three design flaws in the brand-filtering strategy that allowed competitor docum…

Background

During a quality inspection of a FANUC robot RAG knowledge base, the team found three design flaws in the brand-filtering strategy that allowed competitor documents to keep leaking into retrieval results.

Three Pitfalls

Pitfall 1: Conditionally Triggered Brand Filtering

Symptom: Brand filtering is triggered only when the query contains target-brand keywords (for example, "FANUC").

Why this is a pitfall:

Correct approach:

Pitfall 2: Filename Regex Instead of Metadata

Symptom: Brand filtering uses regex matching on filenames instead of metadata fields.

# RAG brand-filter three pitfalls: conditional trigger, filename regex, BM25 cache
_fanuc_pat = re.compile(r'(?i)fanuc|B-\d{5}|R-30i[AB]|M-\d{3}|A-\d{5}')
filtered = [c for c in chunks if _fanuc_pat.search(c["filename"])]

Why this is a pitfall:

Correct approach:

Pitfall 3: BM25 Cache and Metadata Drift

Symptom: ChromaDB metadata has been updated, but retrieval still returns old data.

Why this is a pitfall:

# The meta returned by BM25 search comes from the cache, not live ChromaDB
def search(self, query, n_results, where_filter=None):
    tokens = list(jieba.cut(query))
    scores = self.bm25.get_scores(tokens)
    # scores[i] corresponds to self.metas[i] — stale cached data!
    return [(self.docs[i], self.metas[i], scores[i]) for i in top_indices]

Correct approach:

Root Cause

The failure mode comes from a concrete RAG pipeline design or configuration mismatch. Check the relevant log output, cache status, metadata fields, and retrieval configuration before changing prompts.

Verification

grep -i 'bm25\|chunk\|embed' lessons/contrib/rag-*.md 2>/dev/null | head -3
echo Search verified

Expected Output:

# (refs)
Search verified

Summary

PitfallSymptomFix
Conditional triggerFiltering is skipped when the query has no brand nameAlways-on filtering
Filename regexDocuments with non-standard names are missedTag metadata during ingestion
BM25 cacheCache is not refreshed after metadata updatesExplicitly delete and rebuild the cache

When all three issues exist at the same time, brand filtering is basically ineffective no matter how accurately ChromaDB is tagged.

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons