Skip to main content
ANNOUNCEMENTMeet MariaDB Enterprise Platform 2027. Read more.

Menu

WEBINAR

Built for the Agentic Era: Introducing MariaDB Enterprise Platform 2027

Watch now

Product

When Similar Documents Share One Knowledge Base

By Michael Aglietti

12 min read
Share

Key takeaways

  • The RAG Cross-Contamination Challenge: When scaling knowledge bases with similar documents (such as bank annual reports), standard semantic search can inadvertently retrieve paragraphs from competitors due to shared formats, boilerplate text, and overlapping terminology.
  • The Power of Context Lines: Adding explicit context lines that identify the owner and time period at the start of every chunk helps prevent retrieval pipelines from mixing up data across similar documents.
  • Managed vs. Reference Pipelines: Native retrieval solutions (like MariaDB AI Retrieval) maintain strict document separation out of the box, whereas open reference pipelines require careful configuration—including context lines and rerankers—to prevent cross-document citation errors.
  • Mandatory Citation Validation: Implementing automated post-retrieval checks to verify that every cited source matches the target company and fiscal year is essential to eliminate hallucinations and ensure data integrity.
python
# AI Retrieval builds each chunk's context line from this name,
# for example [Context: example-bancorp-10-k-fy2024].
# slug() turns a company name into lowercase words joined by hyphens.

filing["named"] = f"{slug(filing['company'])}-10-k-fy{filing['year']}.html"
python
# self.scope holds the document IDs of the reports the row is about.
body = {"query": query, "retrieval_method": "hybrid", "top_k": 25,
        "enable_rerank": True, "rerank_top_k": 6}
if self.scope is not None:
    # Set by the application from the report row. The tool's schema has
    # no parameter for it, so the model can't see or change it.
    body["document_ids"] = self.scope
python
# refs: the refs the answer cites. sql and passages: the refs the tools
# returned. company_of("example-bancorp-fy2024#12") returns "example-bancorp".
for ref in refs:
    if ref not in sql and ref not in passages:
        failures.append({"check": "ref_exists", "ref": ref})
    elif ref in passages and company_of(ref) != company:
        failures.append({"check": "company_match", "ref": ref})

When scaling knowledge bases with similar documents, such as bank annual reports or financial filings, standard semantic search can inadvertently retrieve paragraphs from competitor documents due to shared formatting, boilerplate text, and overlapping terminology.

Adding explicit context lines that identify the owner and time period at the start of every text chunk helps retrieval pipelines distinguish between similar documents and avoid mixing up data across sources.

Managed native retrieval solutions like MariaDB AI Retrieval maintain strict document separation out of the box with minimal configuration, whereas open reference pipelines require manual setup, including custom context lines and dedicated rerankers, to prevent citation errors.

Automated post-retrieval checks that verify every cited source matches the correct target company and fiscal year are essential to eliminate hallucinations and ensure data integrity in AI-generated reports.