Skip to content

mstead/budgie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Budget/Spending Analyser

This application serves as my introduction to programming with AI, focusing on implementing Retrieval Augmented Generation (RAG) using a Redis datasource. It allows the user to import spending data via CSV files and allows the user to ask questions about the data that was imported.

Goals

  • Import spending records via a CSV and import into Redis Vector DB
  • Use AI to answer questions based on the data set after pulling RAG data from redis.

Architecture

Data Import

CSV files can be imported using the following CSV format:

name,description,date,category,amount
Groceries,Weekly food shopping at Superstore,2025-04-15,Debit,75.23
Coffee,Morning latte from local cafe,2025-04-16,Credit,5.50

Each row of the CSV is processed, and is stored as a redis document along with an embedding that will be used by AI to determine potential matching records using a vector search. The 'sentence-transformers/all-MiniLM-L6-v2' model is used to create the embedding for each row.

RAG Implementation

Fetching The Initial Data

When a question is asked about the model, an embedding is created based on the question, and a vector query is made to the redis datastore and retrieves the documents that are closely related.

Answering The Answer

To answer the question about the matching data, a text generating AI model is used to analyse the data from the query to provide an answer.

When asking a question to the model, a prompt is created for the particular model and the data from query result is formatted into a table structure and is included as the 'context' used to answer the question.

Final Thoughts And Results

This application only 'sort of works'. The results it produces are never really accurate and based on the questions asked, it often can't produce a reliable answer, if at all. This likely has a lot to with my current knowledge lever of the technology and the models that I've opted to use.

As this was my introduction to AI, I found that there was an incredible learning curve when it comes to the technology and achieving accurate results was difficult. Implementing a basic chatbot is pretty straightforward (which I played with outside of this project) using the tools available, however, building something to solve an isolated problem requires using larger and more fine-tuned models.

This project served as a good introduction the world of AI programming. I'll continue to try and improve this project and evolve it into something that is actually useful.

Installation

Run the redis-stack

$ cd redis-stack
$ podman compose up -d

Create a virtual environment

$ python -m venv .venv
$ . .venv/bin/activate

Install all dependencies

$ pip install --upgrade pip
$ pip install click transformers redisvl langchain_community sentence_transformers pylatexenc pandas accelerate

Usage

The 'budgie' application is a CLI based app.

Commands

$  $ src/budgie --help
Usage: budgie [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  ask
  import-file

Import A Spending Data File

$ src/budgie import-file data/spending.csv

Ask A Question About The Data That Was Imported

 $ src/budgie ask --help
Usage: budgie ask [OPTIONS] QUESTION

Options:
  --model TEXT  The name of the model to use: ['tiny-llama', 'qwen', 'tapas']
  --help        Show this message and exit.
$ src/budgie ask "How many Debit transactions were made on 2025-05-05?"

References

About

Introduction to AI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages