Generative AI typically works on tasks that are narrow and well-defined, such as answering a question, text summarization, text generation and generating a digital image or audio. This project demonstrates a few techniques of Generative AI using Langchain, a popular Python framework.
- A Windows, Linux or Mac machine
- Python 3.13.x or higher
- Langchain - Langchain is a Python framework that enables AI integration by connecting data and APIs with Large Language Models from several vendors.
- Milvus Vector Database - Milvus is an open-source vector database built for Generative AI applications. It supports fast searches, and can scale to tens of billions of vectors with minimal performance loss.
- Docker Desktop - Milvus shall run inside the Docker container.
- bs4 - Beautiful Soup is a library that enables the extraction of content from web pages.
- uv - uv is an extremely fast Python package and project management tool that is optimized for Python Developer happiness. It enables the creation of projects, virtual environments and dependency management. With uv, there is no need to install separate packages like pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and others as uv consolidates the functionality of several Python tools into one unified solution.
- OpenAI API Key
Note - Only a basic knowledge of Python is required to understand and complete this project. There is no proficiency required in the usage of Langchain, Docker, Milvus or uv. All the steps to install and use these tools are explained in the sections below.
-
Install Docker Desktop by following the instructions here. Separate instructions are available for Linux and Mac users.
-
Start Docker Desktop and ensure it is up and running.
-
Install Milvus and run it as a Docker Container by following the instructions below.
Windows
- Create a folder, c:\tools\milvus in the Windows filesystem.
- Download the standalone_embed.bat file from here and copy it to the c:\tools\milvus folder.
- Open a Powershell session in Windows and navigate to the folder, c:\tools\milvus.
cd c:\tools\milvus
- Run the downloaded file to start Milvus as a Docker container. Milvus listens on HTTP port 19530. Do not exit this shell session until the entire project is implemented and tested.
C:\tools\milvus\>standalone_embed.bat start Wait for Milvus starting... Start successfully.
Linux/Mac
- Follow the instructions here to install and run Milvus.
-
Install uv as follows.
Windows
- Create a folder, c:\tools\uv in the Windows filesystem.
- Open a new Powershell session in Windows, navigate to the folder, c:\tools\uv and install uv.
cd c:\tools\uv c:\tools\uv\>powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Exit the Powershell session after uv is installed successfully.
Linux/Mac (TODO)
-
Create a Python project,ai-fest.
Windows
- Create a folder, c:\pythonprojects in the Windows filesystem.
- Open a new Powershell session, navigate to the folder, c:\pythonprojects and execute the following
cd c:\pythonprojects # Create a new Python project called ai-fest using uv. c:\pythonprojects> uv init ai-fest # Switch to the ai-fest project folder. c:\pythonprojects> cd ai-fest # Create a new Python virtual environment using uv. c:\pythonprojects\ai-fest> uv venv # Activate the Python virtual environment. c:\pythonprojects\ai-fest> source .venv/bin/activate # Add the desired Python packages to new Python virtual environment using uv. # Note that the addition of packages via uv finishes in milliseconds. Contrast this with pip, poetry or conda. uv is written in Rust and hence its performance speaks for itself. (ai-fest) tmuralic:\pythonprojects\ai-fest> uv add langchain langchain-core langchain-community langchain-text-splitters langchain-milvus langchain-openai bs4 dotenv # This completes the creation of the project,*ai-fest*. uv has yielded a main.py file with all the project dependencies in the pyproject.toml file. List all the files in the ai-fest folder using dir. c:\pythonprojects\ai-fest>dir main.py pyproject.toml README.md uv.lock # Run the main.py using uv to ensure that the project is configured correctly. c:\pythonprojects\ai-fest>uv run main.py Hello from ai-fest! ```.
-
Copy the following files from GitHub location, to the ai-fest folder. Note that the main.py has to be overwritten with the same file from the GitHub.
- main.py
- simple_rag.py
- README.md
While this project uses OPEN AI as the LLM Provider, this project can integrate with any LLM Provider by making subtle changes within the code. Obtain the OPENAI_API_KEY from here. This key enables the Langchain code to connect to the LLM hosted by OPEN AI.Create a .env (dot env) file in the ai-fest folder and add the OPEN_API_KEY value to it. (Note that the key value below is shown only for illustration and does not represent an actual key)
- OPENAI_API_KEY=skYUacdfER34&MLOPsqzx71hlpwyuq
-
Run the application and watch Retrieval Augmented Generation in action. Review simply_rag.py to understand how RAG is implemented using Langchain.
# Run the main.py. c:\pythonprojects\ai-fest>uv run main.py Running ai-fest app... 2025-06-21 14:02:00,211 [DEBUG][_create_connection]: Created new connection using: 08216138f2004f599a36f8cf740a3d43 (async_milvus_client.py:599) If you have completed Linear Algebra Honors (MA650HO) and Multivariable Calculus Honors (MA670HO) at Choate Rosemary Hall, you are eligible to take the Applied Differential Equations, Honors (MA660HO) course.
-
When all experimentation and testing have been completed, shut down the Milvus Vector Database by typing Control-C in the Windows Powershell session where Milvus was launched.
For further reference, please consider the following:
- Vectors and Embeddings
- Retrieval Augmented Generation
- OpenAI's Playground
- Official Langchain Documentation
- Prompt Engineering Guide
- User, System and Assistant Roles in LLMs
MIT
Free Software, Hell Yeah!