Skip to main content

Retrieval Rails

Retrieval rails execute during RAG (Retrieval-Augmented Generation) pipelines to validate retrieved documents, filter chunks, and fact-check bot responses against the knowledge base.

When Retrieval Rails Execute

Retrieval rails run at two key points in RAG workflows:
Retrieval rails ensure only trusted, relevant, and safe content is used as context for LLM responses.

Built-in Retrieval Rails

Fact Checking with AlignScore

Verifies bot responses against retrieved evidence using information alignment scoring.

Configuration

Action Implementation

From nemoguardrails/library/factchecking/align_score/actions.py:41:
Output mapping:

Self Check Facts

Uses the main LLM to verify responses against retrieved evidence.

Configuration

Action Implementation

From nemoguardrails/library/self_check/facts/actions.py:43:
Mapping function:

AutoAlign Fact Checking

Integration with AutoAlign for advanced fact verification.

Configuration

From examples/configs/autoalign/autoalign_factcheck_config/config.yml:

Sensitive Data Detection in Retrieval

Filter PII from retrieved documents before using as context.

Configuration

Usage in Flows

Usage Examples

Conditional Fact Checking

Only check facts for specific topics: From examples/configs/autoalign/autoalign_groundness_config/rails/factcheck.co:

Custom Accuracy Thresholds

From examples/configs/rag/fact_checking/rails/factcheck.co:
This example shows:
  • Block responses with accuracy < 0.4
  • Warn for accuracy between 0.4 and 0.6
  • Allow for accuracy ≥ 0.6

Multi-Stage Retrieval Validation

Advanced Configurations

Custom Fact Checking Prompts

Override the default fact-checking task prompt:

Chunk-Level Validation

Fallback Strategies

Best Practices

  1. Always validate retrieved chunks - Don’t assume knowledge base quality
  2. Use appropriate thresholds - Tune accuracy thresholds based on domain risk
  3. Provide fallbacks - Have graceful degradation when fact checks fail
  4. Filter sensitive data early - Remove PII before using chunks as context
  5. Cache fact check results - Avoid redundant checks for similar responses
  6. Monitor accuracy scores - Track distribution to tune thresholds

Performance Considerations

Fact-checking adds latency to every RAG response. Consider using it selectively for high-stakes queries.

Troubleshooting

No Evidence Available

AlignScore Endpoint Issues

From the implementation:

See Also