Files
agent-s-rag-pamyatyu/README.md
T
2026-06-30 15:44:59 +03:00

100 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Educational Agent with Retrieval-Augmented Generation (RAG) Memory
This repository contains a lightweight educational agent that demonstrates
Retrieval-Augmented Generation (RAG) using only Python standard libraries.
The implementation is fully selfcontained and does not rely on external
AI services or heavy dependencies, making it suitable for the Deep Agents
Virtual File System environment.
## Features
- **RAG Memory** Stores documents and builds simple bagofwords embeddings.
- **Retrieval Engine** Performs cosinesimilarity based nearestneighbor search.
- **RuleBased Agent** Generates responses by concatenating retrieved context
with a placeholder answer.
- **CLI** Ask a question and receive an answer that includes relevant context.
## Project Structure
```
.
├── src
│ └── index.py # Main implementation
└── README.md # This file
```
## Installation
No external dependencies are required. The code uses only the Python
standard library.
```bash
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git
cd agent-s-rag-pamyatyu
# Ensure you have Python 3.8+ installed
python3 --version
```
## Usage
1. **Prepare a data directory**
Place one or more `.txt` files in a directory. Each file will be
treated as a separate document. Example:
```
data/
├── doc1.txt
├── doc2.txt
└── doc3.txt
```
2. **Run the agent**
```bash
python3 src/index.py --data-dir data --question "What is the capital of France?"
```
The agent will:
- Load all `.txt` files from `data/`.
- Compute bagofwords embeddings for each document.
- Retrieve the top 3 most relevant documents for the question.
- Print the question, retrieved context, and a placeholder answer.
## How It Works
1. **Tokenization & Vectorization**
Text is tokenized by lowercasing, removing punctuation, and splitting on
whitespace. A bagofwords vector (word → count) is created for each
document and for the query.
2. **Similarity Calculation**
Cosine similarity between the query vector and each document vector is
computed using only standard Python data structures.
3. **Retrieval**
The topk documents with the highest similarity scores are returned.
4. **Response Generation**
The agent concatenates the question, the retrieved context snippets,
and a simple placeholder answer.
## Extending the Agent
- **Better Embeddings** Replace the bagofwords approach with a
lightweight embedding model (e.g., a pretrained sentence transformer
loaded locally) if you have the resources.
- **More Sophisticated Generation** Integrate a templatebased or
rulebased system that uses the retrieved context to produce more
informative answers.
- **Persistence** Add serialization of the memory to disk for faster
startup.
## Individual Effort Statement
This work was completed independently by the author and does not rely
on external automated tools or AI services for the core implementation.
## License
MIT License see `LICENSE` for details.