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…
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.
Symptom: Brand filtering is triggered only when the query contains target-brand keywords (for example, "FANUC").
Why this is a pitfall:
Correct approach:
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:
brand: "fanuc" | "kuka" | "abb" | "unknown")Symptom: ChromaDB metadata has been updated, but retrieval still returns old data.
Why this is a pitfall:
bm25_index.pklupdate() changes metadata, the metadata in the BM25 cache is still oldmeta.get("brand", "unknown") in _build_chunk_v2() always return "unknown"# 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:
_build_chunk_v2(): if meta has no brand field, query ChromaDB liveThe 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.
grep -i 'bm25\|chunk\|embed' lessons/contrib/rag-*.md 2>/dev/null | head -3
echo Search verifiedExpected Output:
# (refs)
Search verified| Pitfall | Symptom | Fix |
|---|---|---|
| Conditional trigger | Filtering is skipped when the query has no brand name | Always-on filtering |
| Filename regex | Documents with non-standard names are missed | Tag metadata during ingestion |
| BM25 cache | Cache is not refreshed after metadata updates | Explicitly 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.