76 lines
2.4 KiB
Markdown
76 lines
2.4 KiB
Markdown
# Deep Agent Search with Virtual File System
|
||
|
||
This project demonstrates a simple deep agent search system that operates on **virtual files** stored entirely in memory. It uses **PyTorch**, **scikit-learn**, and **NumPy** to perform TF‑IDF vectorization and cosine similarity ranking.
|
||
|
||
## Features
|
||
|
||
- **Virtual File System**: Create, read, write, unload, and delete virtual files.
|
||
- **Search Agent**: Rank lines from a virtual file based on a query using TF‑IDF and cosine similarity.
|
||
- **Deep Learning Integration**: Uses PyTorch tensors for similarity calculations.
|
||
- **Easy to Extend**: Replace the search logic with more sophisticated models (e.g., transformers) without changing the file system.
|
||
|
||
## Installation
|
||
|
||
```bash
|
||
# Clone the repository
|
||
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove-
|
||
cd 8.-samopisnyy-poiskovyy-agent-na-osnove-
|
||
|
||
# Create a virtual environment (optional but recommended)
|
||
python -m venv venv
|
||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
||
|
||
# Install dependencies
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Usage
|
||
|
||
Run the example script:
|
||
|
||
```bash
|
||
python src/main.py
|
||
```
|
||
|
||
You should see output similar to:
|
||
|
||
```
|
||
Search results for query: 'neural networks'
|
||
1. Neural networks can approximate complex functions.
|
||
2. Deep learning has revolutionized many fields.
|
||
3. PyTorch provides dynamic computation graphs.
|
||
After unload: Cannot read from unloaded file 'sample.txt'.
|
||
```
|
||
|
||
## Project Structure
|
||
|
||
```
|
||
├── src
|
||
│ ├── main.py # Entry point and demo
|
||
│ └── virtual_file_system.py # Virtual file system implementation
|
||
├── requirements.txt # Dependencies
|
||
└── README.md # Documentation
|
||
```
|
||
|
||
## Extending the Search Agent
|
||
|
||
The `SearchAgent` class in `src/main.py` can be replaced with any model that accepts a query and returns ranked results. For example, you could:
|
||
|
||
- Load a pre‑trained transformer (e.g., BERT) and compute embeddings.
|
||
- Use a neural ranking model trained on relevance data.
|
||
- Integrate with external search APIs.
|
||
|
||
Just ensure that the agent receives a `VirtualFileSystem` instance and uses `VirtualFile.read()` to access data.
|
||
|
||
## Testing
|
||
|
||
Unit tests are not included in this minimal example, but you can add tests using `pytest` to verify:
|
||
|
||
- Virtual file read/write/unload behavior.
|
||
- Search agent ranking correctness.
|
||
- Integration of the virtual file system with the agent.
|
||
|
||
## License
|
||
|
||
MIT License
|
||
``` |