Skip to content

A .NET Core 9 RAG (Retrieval-Augmented Generation) console application that uses Ollama.

Notifications You must be signed in to change notification settings

encryptedtouhid/dotnet_console_rag_ollama

Repository files navigation

RAG Console Application with Ollama

A .NET Core 9 RAG (Retrieval-Augmented Generation) console application that uses Ollama for embeddings and chat capabilities. This application allows you to ask questions about your PDF documents with AI-powered responses.

Features

  • PDF document processing and chunking
  • Embedding generation using Ollama's embedding models
  • Simple vector store for semantic search
  • RAG integration with Ollama 3.2 for chat responses
  • Simple console-based chat interface

Requirements

  • .NET 9.0 SDK
  • Ollama 3.2 installed and running locally
  • PDF documents to query

Setup

  1. Install Ollama 3.2 following the instructions at https://ollama.ai/
  2. Pull the required models:
ollama pull nomic-embed-text
ollama pull llama3:8b
  1. Start the Ollama server:
ollama serve
  1. Build the application:
dotnet build
  1. Run the application:
dotnet run

Usage

  1. Place your PDF documents in the Documents folder
  2. Launch the application
  3. The application will automatically process all PDFs in the Documents folder
  4. Type your questions and get AI-powered responses
  5. Type 'exit' to quit the application

How it Works

  1. Document Processing: The application reads PDF files from the Documents folder, extracts text, and chunks it into smaller pieces.
  2. Vector Embedding: Each text chunk is converted into a vector embedding using Ollama's embedding model.
  3. Retrieval: When you ask a question, the application finds the most relevant document chunks by computing cosine similarity between your question and the document embeddings.
  4. Answer Generation: The relevant chunks are sent to Ollama's LLM along with your question to generate a contextually informed answer.

Project Structure

  • Program.cs: Entry point and dependency injection setup
  • Services/: Contains all service implementations
    • IChatService.cs: Interface for chat services
    • OllamaChatService.cs: Implementation for Ollama chat
    • IDocumentProcessor.cs: Interface for document processing
    • PdfDocumentProcessor.cs: PDF document processor implementation
    • IEmbeddingService.cs: Interface for embedding services
    • OllamaEmbeddingService.cs: Ollama embedding service implementation
    • IVectorStore.cs: Interface for vector storage
    • SimpleVectorStore.cs: In-memory vector store implementation
    • IRagService.cs: Interface for RAG services
    • RagService.cs: Main RAG service implementation

Known Limitations

  • In-memory vector store (not persistent between sessions)
  • Only handles PDF documents
  • Requires local Ollama installation
  • Simple text chunking without advanced techniques

About

A .NET Core 9 RAG (Retrieval-Augmented Generation) console application that uses Ollama.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages