A powerful Retrieval-Augmented Generation (RAG) system developed for the Datathon.ai hackathon 2025 Orderfox challenge. This project implements semantic search across large document datasets to retrieve and synthesize information in response to user queries.
Retrieval-Augmented Generation (RAG) is an AI architecture that enhances large language models (LLMs) with the ability to access and use external knowledge. Unlike traditional LLMs that rely solely on their training data, RAG systems:
- Retrieve relevant information from a knowledge base when given a query
- Augment the LLM's context with this retrieved information
- Generate responses that incorporate both the model's inherent knowledge and the retrieved information
This approach addresses hallucination issues in LLMs and allows the model to access up-to-date, specific information that may not have been part of its training data.
-
Dual RAG Agent Architecture:
rag_agent.py: Advanced agent with concept expansion and multi-stage reasoningrag_basic_agent.py: Baseline RAG agent for direct semantic search
-
Interactive UI Interface: User-friendly chat interface built with Gradio
-
Advanced Semantic Processing:
- Prompt expansion for concept discovery
- Semantic search for content retrieval
- Multi-stage answer synthesis
-
Conversational Follow-ups: Maintain context for follow-up questions without re-processing data
-
Customizable Concept Framework:
- Define domain-specific concepts relevant to your business
- Tailor the system to focus on concepts that matter to your use case
- No need to re-embed documents when changing concept definitions
- Embedding Generation: Documents are pre-processed into semantic embeddings
- Query Processing:
- The advanced agent expands queries into multiple concept-specific versions
- The basic agent uses direct semantic matching
- Retrieval:
- Locate relevant content using cosine similarity between query and document embeddings
- Group results by source domains
- Answer Generation:
- Extract and process relevant content
- Synthesize information into coherent responses with source attribution
- Maintain conversation context for follow-up questions
-
Advanced Agent (
rag_agent.py): Uses prompt expansion to explore multiple conceptual angles of a query, generating intermediate answers from each source before creating a comprehensive final response. -
Basic Agent (
rag_basic_agent.py): Takes a more direct approach with single embedding comparison, retrieving all pages from matching domains for a broader but potentially less focused response.
A key advantage of our concept-based RAG approach is that organizations can:
- Define Industry-Specific Concepts: Customize the concept dictionary to focus on dimensions important to your industry
- Maintain Document Scalability: The document embedding process remains independent of concept definitions, preserving scalability
- Optimize at Inference Time: Gain the benefits of conceptual search without additional preprocessing costs
- Evolve Without Reprocessing: Update concept definitions without re-embedding your document collection
This provides the perfect balance between cost-effective document processing and high-precision information retrieval.
For a detailed technical explanation of our concept-based RAG approach and how it improves upon traditional RAG systems, see TECHNICAL_DETAILS.md.
- Python 3.11+
- PyTorch
- Sentence Transformers
- OpenAI API key
- Gradio (for UI)
- Pandas, NumPy, tqdm
- Orderfox Challenge Dataset: This project requires the specific dataset provided by Orderfox for the Datathon 2025 challenge
Before using the system, you must generate the document embeddings:
-
Place the Orderfox-provided challenge dataset in the project directory
-
Run the preprocessing script to create embeddings from your data:
python preprocessing.py
This script:
- Loads the raw document data from the Orderfox dataset parquet file
- Computes semantic embeddings using Sentence Transformers
- Segments the data into manageable chunks
- Saves the processed data as parquet files with embedding vectors
Note: The preprocessing can take significant time depending on your dataset size and hardware capabilities.
To customize the system for your specific needs:
- Edit the concept dictionary in
rag_agent.pyto focus on aspects most relevant to your business - No need to reprocess your document embeddings - changes take effect immediately
- Test with domain-specific queries to fine-tune your concept definitions
Launch the user interface with:
python rag_ui.pyThe UI provides:
- Input field for your query
- Real-time status updates
- Response display
- Chat history for follow-up questions
Key parameters can be adjusted in the agent files:
num_tokens_prompt_expansion: Controls detail in concept explorationnum_tokens_intermediate_answer: Limits intermediate processing stepsnum_tokens_final_answer: Sets maximum response lengthmax_good_subpage_links: Controls breadth of source retrievalconcept_dict: Define the business-specific concepts to enhance search relevance
The system works with document embeddings stored in parquet files with the following schema:
home_url: Source domainpage_url: Specific page URLtext: Document contentembd_vector: Pre-computed semantic embedding vector
- Built for the Datathon.ai 2025 RAG-Orderfox challenge
- Dataset provided by Orderfox, the world's largest AI-powered CNC network and B2B Chatbot provider
- Powered by:
- Sentence Transformers
- OpenAI API
- Gradio UI framework

