DEV Community

Cover image for Building a RAG Agent for Pharmacy Stock Optimization with Gemini, ChromaDB and LangGraph

Building a RAG Agent for Pharmacy Stock Optimization with Gemini, ChromaDB and LangGraph

Introduction

FarmaStock AI is an academic Generative AI project focused on a real-world problem: how to make pharmacy stock analysis easier to understand and explore.

In community pharmacy, stock information is not always straightforward. Sales, purchases, manual stock corrections and inventory movements can appear across different exports or operational records. This makes it difficult to quickly understand what happened with a product, why stock changed, or what kind of analytical logic should be applied before making replenishment decisions.

The goal of this project was not to replace a pharmacy management system. Instead, I wanted to build a domain-specific AI assistant capable of answering questions about pharmacy stock logic, data preparation, analytical decisions and future optimization opportunities.

The result is FarmaStock AI: a Retrieval-Augmented Generation assistant built with Python, LangGraph, ChromaDB, Gemini and Streamlit.

The context and dataset

The project is based on a realistic pharmacy stock optimization scenario. The main source of information comes from the type of exports that a pharmacy management system can generate: product movements, sales records, purchases, current stock and manual stock modifications.

One of the most important challenges is that not every stock change has the same meaning. For example, a sale reduces stock, a purchase increases stock, and a manual modification may represent either a correction, a stock count adjustment or an implicit replenishment depending on the previous stock value.

Because of this, the project focuses heavily on documenting the business logic behind stock reconstruction. The assistant is designed to retrieve that context and explain it clearly when the user asks about the analytical process.

Technical approach

The project follows a Retrieval-Augmented Generation architecture. Instead of asking a language model to answer from general knowledge, I created a workflow where the model first receives relevant project-specific context.

The main components are:

Python as the core development language.
Streamlit as the user interface.
ChromaDB as the vector database for document retrieval.
Gemini as the language model used to generate grounded answers.
LangGraph to organize the assistant workflow into clear steps.
Markdown documentation to describe the domain logic and technical decisions.

At a high level, the workflow is:

The user asks a question through the Streamlit interface.
The system retrieves the most relevant project context from ChromaDB.
LangGraph orchestrates the interaction flow.
Gemini generates an answer using the retrieved context.
The final response is displayed in the Streamlit app.

This structure makes the assistant easier to explain, test and extend compared with a simple single-prompt chatbot.

Results

The final result is a working AI assistant that can answer questions about the project, the pharmacy stock domain, the data preparation logic and the technical architecture.

Some of the main outcomes are:

A functional RAG assistant focused on pharmacy stock analysis.
A Streamlit interface that makes the project easy to demonstrate.
A LangGraph-based workflow that separates retrieval, reasoning and response generation.
A ChromaDB retrieval layer for grounding answers in project documentation.
A GitHub repository structured as a professional academic project.

The most valuable part of the project is not only the assistant itself, but the way it connects Generative AI with a specific business domain. In this case, my background in pharmacy helped me define a more realistic use case and identify the kind of questions a user might actually ask.

What I learned

This project helped me understand the difference between building a notebook and building a usable AI prototype.

A notebook can show the technical process, but a Streamlit application makes the project easier to communicate. Similarly, a language model can generate answers, but a RAG system makes those answers more connected to the actual project documentation.

I also learned that the quality of a Generative AI project depends heavily on the quality of the context, the clarity of the workflow and the way the solution is presented to the user.

If I continued developing the project, the next steps would be:

Connect the assistant to real pharmacy exports.
Add a structured evaluation set with domain-specific questions.
Show retrieved chunks in the interface for better traceability.
Expand the analytical layer with forecasting and reorder recommendations.
Build a dashboard to combine stock KPIs with AI-generated explanations.
Repository

You can find the GitHub repository here:

https://github.com/dalvaromartinez/farmastock-ai-rag-agent

Final note

This project was developed as an academic project during the Master in Artificial Intelligence at Evolve.

It combines Generative AI, retrieval systems and a real-world pharmacy analytics use case to demonstrate how AI assistants can support technical understanding and decision-making in a specific domain.

Top comments (0)