feat: solution for '8. Самописный поисковый агент на основе deep agents from scratch'
CI / build (3.1) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled

This commit is contained in:
2026-06-30 16:22:52 +03:00
parent df9e4f49d2
commit 1039c7065c
14 changed files with 524 additions and 512 deletions
+20 -74
View File
@@ -1,97 +1,43 @@
# Deep Agent Search
# DeepAgent
A lightweight search agent that uses a simple neural embedding model to retrieve
documents from a corpus. The agent is implemented in pure Python with
PyTorch and demonstrates how deep learning can be applied to information
retrieval without relying on external services.
> **Author**: Artur Kuzakhmetov
> **Course**: DeepAgents Perplexity (Lecture 09.04.2026)
> **Deadline**: 31.08.2026
## Features
- **Custom neural encoder** word embeddings trained from scratch.
- **Cosine similarity ranking** fast and interpretable.
- **Commandline interface** run searches directly from the terminal.
- **Unit tests** ensure correctness of embeddings, similarity, and ranking.
- **No external services** everything runs locally on CPU or GPU.
DeepAgent is a minimal example of a deep learning based search agent.
It demonstrates how to combine a neural network with a simple search algorithm
(MonteCarlo Tree Search style) without relying on external search libraries.
## Installation
```bash
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove-<repo>.git
cd 8.-samopisnyy-poiskovyy-agent-na-osnove-<repo>
# Create a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\\Scripts\\activate`
# Install dependencies
pip install -r requirements.txt
# Install the package
pip install .
```
> **Note**: The project requires Python3.8+ and PyTorch ≥ 1.8.0.
## Usage
### Commandline
```bash
python -m src.main "deep learning models"
```
The script prints the top 5 results with relevance scores.
### Programmatic
```python
from src.agent import SearchAgent
from src.search_agent import SearchAgent, PolicyValueNet
corpus = [
"Deep learning models can capture complex patterns in data.",
"Search engines index documents to provide relevant results.",
# ...
]
# Create a policyvalue network
net = PolicyValueNet(input_dim=1, action_space=2)
agent = SearchAgent(corpus)
results = agent.search("deep learning", top_k=3)
# Create the agent
agent = SearchAgent(policy_value_net=net, max_depth=3)
for res in results:
print(f"Doc {res.doc_id} (score={res.score:.4f}): {res.text}")
# Run the agent on a simple state
state = 0
action = agent.act(state)
print(f"Chosen action: {action}")
```
## Testing
Run the unit tests with:
## Running Tests
```bash
python -m unittest discover -s tests
pytest
```
All tests should pass:
```
$ python -m unittest discover -s tests
....
----------------------------------------------------------------------
Ran 6 tests in 0.12s
OK
```
## Extending the Agent
- **Training** call `agent.train()` to finetune embeddings on the corpus.
- **Custom tokenizer** replace `_tokenize` in `src/agent.py` with a more advanced tokenizer.
- **Different similarity** swap `cosine_similarity` with dotproduct or Euclidean distance.
## License
This project is released under the MIT License.
---
**Academic Integrity**
All code is written from scratch by the student. No external services or pretrained models are used. The implementation follows the assignment guidelines and respects the deadline of 31.08.2026.
MIT License see the [LICENSE](LICENSE) file for details.