Question & Answer (Q&A) Building Block¶
Natural language interfaces to interact with data through RAG (Retrieval-Augmented Generation) and Text-to-SQL powered by IBM watsonx.
Overview¶
This building block enables users to query and interact with data using natural language, making data more accessible to both technical and non-technical users.
Components¶
1. RAG (Retrieval-Augmented Generation)¶
RAG Accelerator¶
The RAG Accelerator provides a complete RAG pipeline with document processing, embedding generation, and semantic search capabilities. It's a deployable API that simplifies ingestion and querying while offering extensible customization options.
Features¶
- Ingestion Pipeline: Chunking, merging, and ingestion into Milvus
- Embedding: Dense, hybrid, or dual embeddings with selectable models
- Retriever & Querying: Hybrid search, reranking (weighted, RRF, cross-encoder), configurable search parameters
- LLM Integration: Configurable models and prompt templates
- Governance: Integration with watsonx.governance for build-time and runtime governance
Key Capabilities¶
Ingestion Customization:
- Document loaders: HTML, JSON, PDF, Markdown, custom loaders
- Collection schema: Configurable via JSON templates
- Embedding models: Hybrid, dense, dense+sparse (HuggingFace, watsonx.ai, IBM models)
- Document processing: Docling/Markdown processing, picture annotation, table cleanup
- Chunkers: Docling hybrid chunker, Markdown text splitter, recursive text splitter
Querying Customization:
- Search parameters: Number of docs retrieved and reranked
- Rerankers: Weighted, RRF, cross-encoding
- LLM models: Configurable by provider and prompt template
Prerequisites¶
Requirements
- Python 3.13 installed locally
- Milvus DB Credentials
- IBM watsonx.ai environment with project and necessary access control
- IBM COS Credentials
- git installed locally
Getting Started¶
-
Clone the repository:
git clone https://github.com/ibm-self-serve-assets/building-blocks.git cd building-blocks/data-for-ai/question-and-answer/rag/assets/rag-accelerator -
Create a Python virtual environment:
python3 -m venv virtual-env source virtual-env/bin/activate pip3 install -r requirements.txt -
Configure environment variables:
cp env .env -
Update
.envwith your credentials: - Milvus credentials:
WXD_MILVUS_HOST,WXD_MILVUS_PORT,WXD_MILVUS_USER,WXD_MILVUS_PASSWORD - watsonx.ai credentials:
WATSONX_MODEL_ID,WATSONX_PROJECT_ID,WATSONX_APIKEY,WATSONX_URL - IBM COS credentials:
IBM_CLOUD_API_KEY,COS_ENDPOINT,COS_AUTH_ENDPOINT,COS_SERVICE_INSTANCE_ID - REST_API_KEY: Set a unique value for API authentication
Running the Service¶
Start the application:
python3 main.py
Or using Uvicorn:
uvicorn app.main:app --host 127.0.0.1 --port 4050 --reload
Access Swagger UI at: http://127.0.0.1:4050/docs
API Endpoints¶
Ingestion Endpoint:
POST /ingest-files
Request body:
{
"bucket_name": "<cos-bucket>",
"collection_name": "<milvus-collection>",
"chunk_type": "DOCLING_DOCS"
}
Query Endpoint:
POST /query
Request body:
{
"collection_name": "<milvus-collection>",
"query": "<query text>"
}
2. Text-to-SQL¶
The Text-to-SQL component converts natural language questions into executable SQL queries using watsonx.data intelligence.
Features¶
- Natural language to SQL conversion
- Metadata enrichment for improved query accuracy
- Integration with watsonx.data and watsonx.ai
- Support for multiple database connections
Architecture¶
Prerequisites¶
Requirements
- IBM watsonx.data instance
- IBM watsonx.ai access
- Presto connection configured
- Python 3.x environment
Getting Started¶
-
Navigate to the Text-to-SQL directory:
cd building-blocks/data-for-ai/question-and-answer/text-to-sql/assets/asset-1 -
Set up metadata enrichment:
cd metadata_enrichment_text2sql pip install -r requirements.txt -
Configure
config.pywith your credentials and connection details -
Run the metadata enrichment:
python main.py
Deployment Options¶
The Text-to-SQL application can be deployed on:
- IBM Code Engine: See Code Engine Setup
- Red Hat OpenShift: See OpenShift Setup
Use Cases¶
- Customer Support: Enable natural language queries over support documentation
- Business Intelligence: Allow business users to query data without SQL knowledge
- Data Exploration: Facilitate quick insights from large datasets
- Knowledge Management: Build searchable knowledge bases with semantic search
Coming Soon¶
Upcoming Features
- .png and .jpg VLM Support
- Additional docling processing functions (image annotation, table exports)
- Prompt Controls & Guardrails
- Governance SDK with evaluation capabilities
- Memory Layers for multi-turn Q&A
- Enhanced error logging
IBM Products Used¶
This building block leverages the following IBM products and services:
IBM watsonx.ai¶
Enterprise-ready AI and data platform for building, deploying, and managing AI models.
- Purpose: LLM integration for RAG and Text-to-SQL generation
- Documentation: IBM watsonx.ai Documentation
- Getting Started: watsonx.ai Quick Start
IBM watsonx.data¶
Open, hybrid, and governed data store built on an open lakehouse architecture.
- Purpose: Vector database (Milvus) hosting and data management
- Documentation: IBM watsonx.data Documentation
- Getting Started: watsonx.data Getting Started
IBM watsonx.data Intelligence¶
AI-powered data intelligence and governance platform.
- Purpose: Text-to-SQL generation with metadata enrichment
- Documentation: watsonx.data Intelligence Documentation
- Getting Started: Setting up watsonx.data Intelligence
IBM Cloud Object Storage (COS)¶
Scalable, secure object storage for unstructured data.
- Purpose: Document storage for RAG ingestion pipeline
- Documentation: IBM COS Documentation
- Getting Started: COS Getting Started
Milvus Vector Database¶
Open-source vector database for AI applications (hosted on watsonx.data).
- Purpose: Vector storage and semantic search for RAG
- Documentation: Milvus Documentation
- Integration: Milvus on watsonx.data
Demo Videos¶
RAG Accelerator Demo¶
Watch the RAG Accelerator in action, demonstrating the complete RAG pipeline from document ingestion to semantic question answering:
Demo Highlights:
- Document ingestion from IBM Cloud Object Storage (COS)
- Docling-based document parsing and chunking
- Embedding generation using IBM watsonx.ai
- Vector storage and indexing in Milvus
- Semantic search and retrieval
- RAG-powered question answering with LLM
Text-to-SQL Demo¶
Watch the Text-to-SQL application convert natural language questions into executable SQL queries using metadata-enriched prompts:
Demo Highlights:
- Natural language question input
- Metadata enrichment from watsonx.data Intelligence
- SQL query generation using IBM watsonx.ai
- Query execution against watsonx.data
- Result display and formatting
- Error handling and query refinement
Team¶
Created and Architected By: Anand Das, Anindya Neogi, Joseph Kim, Shivam Solanki