How yashnayi234/retrieval-augmented-generation-custom-chatbot---genai works
Project Overview
• This project is a domain-specific chatbot built using a Retrieval-Augmented Generation (RAG) approach for financial queries.
• It leverages financial data (CSV dataset) and integrates OpenAI’s API for generating context-aware responses.
• The implementation is organized primarily around a Jupyter Notebook (for interactive use), which orchestrates data loading, embedding computation, retrieval via cosine similarity, prompt construction, and final answer generation.
Main Components
a. Data Source:
• Financial Dataset (“finanical_rag_embedding_dataset.csv”) that contains domain-specific data (text entries, and possibly precomputed embeddings).
b. Data Preparation & Preprocessing:
• A module or code segment for loading and cleaning the CSV data.
• Preprocessing routines for embedding computation (if not already computed).
c. Embedding & Retrieval Module:
• Implements the embedding generation (using pre-trained models) and cosine similarity computation to retrieve relevant context.
• Responsible for efficiently filtering down the dataset entries based on relevance.
d. Prompt Construction Module:
• Dynamically builds the prompt, integrating the retrieved context with the user query.
• Takes into account customizations like token limits (max_prompt_tokens, max_answer_tokens) and a flexible prompt template.
e. OpenAI API Integration:
• A component that sends the constructed prompt to the OpenAI API.
• Manages receiving and processing the generated response.
f. User Query / Interactive Interface:
• The Jupyter Notebook acts as an interactive front end where queries are inputted and results are displayed.
Relationships and Data Flow
• The user inputs a financial query into the notebook interface.
• Data Preprocessing:
• The query may trigger the data preparation routines that load or preprocess the CSV dataset.
• Embedding & Retrieval:
• The project computes or uses precomputed embeddings.
• It runs a cosine similarity search to find the most relevant financial contexts.
• Prompt Construction:
• The retrieved context is combined with the query (using the custom prompt template) to form a final prompt.
• API Call:
• The prompt is sent to the OpenAI API, and the response is received.
• Response Return:
• The response is then relayed back to the user, all orchestrated within the notebook.
Architectural Patterns and Design Principles
• Modular Design: Each stage (data ingestion, processing, retrieval, prompt construction, API communication) is conceptually separated, making the architecture clean and extendable.
• Reusability and Customization: The prompt template and token limit parameters allow for significant flexibility.
• Integration Centric: Strong reliance on external services (OpenAI API) and established libraries (Pandas, SciPy) for robust performance.