Back to all projects
FinIQ - A Financial Product Discovery Engine
Data & AI Product

Role

I acted as the Product Manager and Developer, I was responsible for:

1Defining MVP scope and objectives
2Define how success will look like for MVP
3Coding the MVP
4Measure the successful
5Post-MVP write PRD
6SoPs and User Trainings
7Continuous Measurement

Why Are We Building This?

The CX team, at a wealth-tech platform, faces challenges in quickly answering product-centric questions from customers due to a lack of in-depth product understanding. Custom product comparisons are time-consuming as the team needs to navigate through multiple documents to compare products. This leads to:

1Longer response times to customer inquiries
2Inconsistent information provided to customers
3Reduced customer satisfaction and potential loss of business
4Inefficient use of advisors' time and resources

What Is the Solution?

To address these challenges, I proposed building a Gen AI RAG (Retrieval Augmented Generation) system that follow below architecture.

Key building blocks

User application: The interface through which users interact with the system.
Prompt: The initial query or input provided by the user.
External information sources: Contains the vector database and documents used for retrieval.
Vector database: Stores vector representations of documents for efficient similarity search.
Documents: The original text documents containing information.
Generate vector embeddings: Converts the user's prompt into a vector representation.
Vector embeddings: The numerical representation of text used for similarity comparisons.
Retrieve similar documents: Finds relevant documents based on vector similarity.
Rerank based on relevancy: Further refines the retrieved documents for better accuracy.
LLM (Large Language Model): The AI model that generates human-like text responses.
Completion: The final response generated by the LLM based on the augmented prompt.

How it was implemented

Tech Stack

LLM Model: OpenAI's GPT 3.5 turbo and 4o - ‣
Pinecone for vector database storage - ‣
SQLite for relational database management - ‣
Wrapper: LangChain for orchestrating the RAG pipeline - ‣
Streamlit for creating the user interface - ‣

Coding

Actual code:

Import the core libraries such as Langchain, Pandas and OpenAI.

import pandas as pd
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain.agents import Tool, AgentExecutor
# ... (other imports)

Configuration and Environment

The chatbot's environment is carefully configured to ensure optimal performance. We set up the OpenAI API key, initialize the language model and embeddings, and configure the Pinecone vector store for efficient information retrieval.

llm_model = "gpt-4o"
os.environ["OPENAI_API_KEY"] = "--"
llm = ChatOpenAI(model=llm_model, temperature=0)
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")

Specialized Agent Functions

The heart of chatbot lies in its specialized agent functions. These functions are designed to handle specific types of financial queries with precision:

1Returns Agent: Processes queries related to asset returns, utilizing a SQLite database of financial data.
2Subscription and Redemption Cutoff Agents: Handle inquiries about important dates for financial transactions.
3Factsheet RAG (Retrieval-Augmented Generation): Provides detailed information from fund factsheets using advanced document retrieval and processing techniques.

Each agent function is tailored to its specific domain, ensuring accurate and relevant responses.

Tool Definitions

The chatbot's capabilities are extended through a set of custom tools:

SubsCutoffTool = Tool(
    name='Subscription Cutoffs',
    func=subs_cutoffs_agent,
    description="Answers questions about kristal cutoff dates and applicable month-end NAV dates for subscriptions"
)
# ... (other tool definitions)

These tools encompass various financial operations, from handling cutoff dates to performing complex calculations and querying JSON data.

The Brain: Agent Setup

The chatbot's intelligence is powered by a sophisticated agent setup:

agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools,
                               memory=conversational_memory,
                               handle_parsing_errors=True,
                               verbose=True)

This setup includes a react agent with access to all defined tools, conversational memory to maintain context, and error handling for robustness.

Query Enhancement

One of the most important things to finetune the response of the LLM.

We have implemented several prompting techniques:

1A custom prompt for react agent.
2agent = create_react_agent(llm, tools, prompt)
3A prompt to enhance the user query(correct grammatical mistakes and add the name of the tool to be used so that agent doesn’t need to think much)
4rewriter = rewrite_prompt | ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0) | StrOutputParser() | _parse
5A few-shot example as a prompt for SQL agent.
6examples = [ { "input": "Count the total number of unique assets in the dataset.", "query": "SELECT COUNT(DISTINCT Asset) AS total_unique_assets FROM 'merged_returns_idx_2_table';" }, { "input": "Calculate the average return for the date '2023-12-29' across all assets.", "query": "SELECT AVG(`2023-12-29 00:00:00`) AS average_return_on_2023_12_29 FROM 'merged_returns_idx_2_table';" }, { "input": "Find the maximum and minimum return for the date '2023-12-29' for each Asset Type Exposure.", "query": "SELECT Asset_Type_Exposure, MAX(`2023-12-29 00:00:00`) AS max_return, MIN(`2023-12-29 00:00:00`) AS min_return FROM 'merged_returns_idx_2_table' GROUP BY Asset_Type_Exposure;" }, { "input": "Calculate the sum of returns for each month in the year 2023 for the asset with ticker 'XLY'.", "query": "SELECT SUM(`2023-12-29 00:00:00`) AS Dec_2023, SUM(`2023-11-30 00:00:00`) AS Nov_2023, SUM(`2023-10-31 00:00:00`) AS Oct_2023, SUM(`2023-09-29 00:00:00`) AS Sep_2023, SUM(`2023-08-31 00:00:00`) AS Aug_2023, SUM(`2023-07-31 00:00:00`) AS Jul_2023, SUM(`2023-06-30 00:00:00`) AS Jun_2023, SUM(`2023-05-31 00:00:00`) AS May_2023, SUM(`2023-04-28 00:00:00`) AS Apr_2023, SUM(`2023-03-31 00:00:00`) AS Mar_2023, SUM(`2023-02-28 00:00:00`) AS Feb_2023, SUM(`2023-01-31 00:00:00`) AS Jan_2023 FROM 'merged_returns_idx_2_table' WHERE Asset_Ticker = 'XLY';" },]

User Interface: Streamlit App

The chatbot is wrapped in a sleek Streamlit web application, providing an intuitive interface for users to interact with the system:

def main():
    st.title("Kristal Chatbot")
    user_input = st.text_input("User: ")
    if st.button("Ask", use_container_width=True):
        # Process query and display response

This interface allows users to input their financial queries and receive instant, detailed responses.

Evaluation & Feedback

I am developing a robust evaluation mechanism to benchmark its performance against industry standards. The approach involves comparing our custom model with leading market-standard language models using a single, carefully selected financial document as input. This method allows us to assess our chatbot's ability to comprehend and generate accurate responses based on limited but diverse financial information. The scales on which model will be evaluated is - Helpfulness, Honesty and Harmlessness (HHH).

References

1https://python.langchain.com/docs/modules/tools/custom_tools/
2https://python.langchain.com/docs/modules/agents/agent_types/react/
3https://python.langchain.com/docs/modules/agents/
4https://python.langchain.com/docs/use_cases/sql/agents/
View all projects