Skip to main content
The PubChem RAG (Retrieval-Augmented Generation) module enriches chemistry queries by automatically fetching relevant compound information from the PubChem database.

Overview

The RAG pipeline extracts chemistry terms from your query, retrieves compound data from PubChem, and uses this context to provide more informed responses.
1

Term Extraction

Extract chemistry-related terms using SpaCy NLP
2

PubChem Query

Fetch compound descriptions from PubChem API
3

Context Augmentation

Combine retrieved data with original query
4

LLM Response

Generate informed answer using augmented context

Basic Usage

Using the —use_rag Flag

Direct Module Usage

How It Works

1. Term Extraction

The extract_terms.py module uses SpaCy to identify chemistry-related terms:
Example:

2. PubChem Data Fetching

The pubchem_fetcher.py module queries multiple PubChem API endpoints:

3. Complete Pipeline

Integration with Agent

When using process_input() with RAG enabled (plan_execute_agent/rdkit_agent.py:334):

Use Cases

Compound Identification

Get detailed information about named compounds

Property Lookup

Retrieve physical and chemical properties

Bioactivity Data

Access biological activity information

Safety Information

Fetch toxicity and hazard data

Examples

Compound Information

Drug Interactions

Chemical Classes

With Agent for Complete Workflow

Combining with Image Processing

Use both RAG and image extraction for comprehensive analysis:

PubChem API Endpoints

The module queries three endpoint types:

Custom Term Extraction

You can customize term extraction for domain-specific needs:

Error Handling

Performance Optimization

Caching Results

Batch Processing

Best Practices

  • Use specific chemical names when possible
  • Include context about what information you need
  • Mention related compounds for comparative queries
  • Be explicit about desired properties
  • Cache frequent queries to avoid API rate limits
  • Batch similar queries together
  • Use specific terms to reduce irrelevant results
  • Consider local database for high-volume usage
  • Verify critical information from multiple sources
  • Cross-reference with original PubChem entries
  • Be aware of data currency (last update dates)
  • Validate chemical structures independently

Limitations

  • Requires internet connection to PubChem API
  • Subject to PubChem API rate limits
  • Term extraction may miss domain-specific terminology
  • Quality depends on PubChem data completeness
  • Not all compounds are in PubChem database

See Also