To run this code, you need to have Ollama installed and running in the background. You also need to have a text file named "text.txt" with the text you want to use as a knowledge base.
- Install Ollama: https://ollama.com/
- Keep Ollama running in the background
- Pull desired model from Ollama. In the terminal:
$ ollama pull <model_name> - Create a virtual environment and activate it:
$ python -m venv .venv$ source .venv/bin/activate - Install the necessary packages:
$ pip install --upgrade pip$ pip install langchain langchain-community langchain-huggingface sentence_transformers chromadb unstructured - Create a text file named "text.txt" with the text you want to use as a knowledge base. In this example, the text.txt file contains the 3 volumes from "The Lord of the Rings" by J.R.R. Tolkien.
- Run the code below:
python3 main.py
Stack: Python, LangChain, Ollama, ChromaDB
- Based on the article Using Langchain and Open Source Vector DB Chroma for Semantic Search with OpenAI's LLM from Pradip Nichite.