A console application that uses Retrieval Augmented Generation (RAG) to answer user questions based on processed text snippets.
This application processes a text file (e.g., assets/book.txt) to create a searchable database of content. Users can ask questions, and the application streams answers derived strictly from the context provided by the processed text. If the answer cannot be directly derived from the available context, the response will indicate uncertainty.
Inspired on: https://github.com/mtayyab2/RAG
- Language: C#
- Platform: .NET 9
- Libraries:
+----------------+
| Program.cs |
+----------------+
|
v
+----------------------+
| Database (DuckDB) |
+----------------------+
|
v
+----------------------+
| TextProcessor |
| (ProcessFile) |
+----------------------+
|
v
+----------------------+
| LLM Service |
| (AskQuestionStream) |
+----------------------+
This diagram outlines the main components and their interactions:
- Program.cs initializes the application and database.
- TextProcessor processes the text file into indexed snippets.
- LLM Service handles user queries by retrieving context from the snippets and streaming answers using the LLM.
-
Initialization:
- The application initializes necessary configurations and a database connection.
- It starts by processing the text file located at
assets/book.txt.
-
Text Processing:
- The
TextProcessorreads the file and processes its content, preparing snippets to be used for context in question answering.
- The
-
Question & Answer Flow:
- The console prompts the user to input a question.
- The question, along with the context derived from the processed text, is sent to the LLM service.
- The LLM answers the question using only the provided context and streams the response back to the console.
- Users can repeatedly ask questions or type
exitto close the application.
-
Prerequisites
- .NET 9 SDK
- Visual Studio 2022 or any compatible IDE is recommended.
-
Setup and Installation
- Clone the repository:
https://github.com/ricardodemauro/RAG-Simple - Navigate to the project directory:
cd llm-rag-console-app - Restore dependencies:
dotnet restore
- Clone the repository:
-
Running the Application
- Build the project:
dotnet build - Run the application:
dotnet run - Follow the instructions in the console:
- Enter a question when prompted.
- View the answer as it streams in.
- Type
exitto terminate the app.
- Build the project:
This LLM RAG Console App combines text processing, a searchable context database, and a powerful LLM to provide concise and accurate answers to user questions based entirely on supplied content. Enjoy using the app, and feel free to contribute or suggest improvements!