Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pranavkrishnasuresh/chemAgent/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The query_chemistry.py module serves as the primary RAG (Retrieval-Augmented Generation) runner script that orchestrates the entire chemistry query pipeline. It integrates term extraction, PubChem data retrieval, and LLM response generation.

Functions

The main entry point for processing chemistry-related queries through the RAG pipeline.
query_text
str
required
The user’s chemistry question or query text to process
response
str
The generated LLM response based on PubChem context, or an error message if no relevant information is found

Pipeline Flow

The function executes a three-step RAG pipeline:
  1. Term Extraction: Uses extract_chemistry_terms() to identify chemistry-related terms from the query
  2. Data Retrieval: Calls fetch_pubchem_data() to retrieve relevant information from PubChem API
  3. Response Generation: Invokes generate_llm_response() to synthesize a contextual answer using the retrieved data

Example Usage

from plan_execute_agent.pubchem_rag import query_chemistry_related

# Query about a chemical compound
response = query_chemistry_related("What is the molecular structure of aspirin?")
print(response)

# Query about chemical properties
response = query_chemistry_related("Tell me about the properties of benzene")
print(response)

Return Behavior

# Successful response
"Aspirin (acetylsalicylic acid) is a salicylate drug..."

# No chemistry terms found
"No chemistry-related terms found in the query."

# No PubChem data available
"No relevant information found on PubChem."

Integration with ChemAgent

This function is called by the ChemAgent’s planning and execution workflow when:
  • A user query requires factual chemistry knowledge
  • Chemical compound information needs to be retrieved
  • The agent needs to augment its response with authoritative data from PubChem
The RAG approach ensures responses are grounded in reliable scientific data rather than relying solely on the LLM’s training data.

Source Location

plan_execute_agent/pubchem_rag/query_chemistry.py:13

Build docs developers (and LLMs) love