A local Retrieval-Augmented Generation (RAG) system built with LlamaIndex, using Ollama for local LLM inference and Hugging Face embeddings.
- Local LLM Integration: Uses Ollama to run language models locally
- Vector Search: Implements semantic search using Hugging Face embeddings
- Document Processing: Automatically chunks and indexes documents
- TypeScript Support: Full TypeScript implementation with type safety
- Privacy-First: All processing happens locally - no data sent to external APIs
- Node.js (v16 or higher)
- Yarn package manager
- Ollama installed and running locally
-
Clone the repository:
git clone https://github.com/Mimi848/LlamaIndexRAG-Implementation.git cd LlamaIndexRAG-Implementation
-
Install dependencies:
yarn install
-
Install and setup Ollama:
# Install Ollama (macOS) brew install ollama # Or download from https://ollama.com # Pull the required model ollama pull mistral
-
Start Ollama service:
ollama serve
-
Run the RAG system:
yarn start # or npx tsx vectorIndexLocal.ts
The script will:
- Load the example document (
abramov.txt
) - Create embeddings and build a vector index
- Query the document with: "What did the author do in college?"
- Return an AI-generated response based on the document content
├── vectorIndexLocal.ts # Main RAG implementation
├── package.json # Dependencies and scripts
├── yarn.lock # Dependency lock file
├── .gitignore # Git ignore rules
└── README.md # This file
The system uses Mistral by default. To change the model:
Settings.llm = new Ollama({
model: "mistral", // Change to your preferred model
});
Available models (pull with ollama pull <model>
):
mistral
(default)llama2
codellama
mixtral:8x7b
Uses Hugging Face's BAAI/bge-small-en-v1.5
for embeddings:
Settings.embedModel = new HuggingFaceEmbedding({
modelType: "BAAI/bge-small-en-v1.5",
});
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: "What is the main topic of the document?",
});
console.log(response.toString());
// Load your own document
const essay = await fs.readFile("path/to/your/document.txt", "utf-8");
const document = new Document({ text: essay, id_: "custom-doc" });
// Create index
const index = await VectorStoreIndex.fromDocuments([document]);
-
Ollama Connection Error:
- Ensure Ollama service is running:
ollama serve
- Check if the model is available:
ollama list
- Ensure Ollama service is running:
-
Missing Model Error:
- Pull the required model:
ollama pull mistral
- Pull the required model:
-
Memory Issues:
- Use smaller models like
mistral
instead ofmixtral:8x7b
- Reduce document size for processing
- Use smaller models like
You may see deprecation warnings about @llamaindex/cloud
- these are harmless and don't affect functionality for local usage.
- llamaindex: Core LlamaIndex library
- @llamaindex/ollama: Ollama integration
- @llamaindex/huggingface: Hugging Face embeddings
- typescript: TypeScript support
- tsx: TypeScript execution runtime
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes
- Run tests:
yarn test
(if available) - Commit changes:
git commit -m 'Add feature'
- Push to branch:
git push origin feature-name
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review LlamaIndex documentation
- Open an issue in this repository