60 lines
2.7 KiB
Markdown
60 lines
2.7 KiB
Markdown
**What was implemented**
|
||
|
||
- A lightweight in‑memory *Virtual File System* (`VirtualFileSystem`) that can create, retrieve, delete, list and unload files.
|
||
- Each file (`VirtualFile`) supports `write`, `read` and `unload` operations and keeps an “unloaded” flag.
|
||
- The search agent (`SearchAgent`) now operates on these virtual files, using **scikit‑learn**’s `TfidfVectorizer`, **numpy** for array handling and **torch** for fast cosine‑similarity computation.
|
||
- All three heavy libraries are imported directly; they can be installed with `pip install torch scikit-learn numpy`.
|
||
|
||
**Why the main parts satisfy the requirements**
|
||
|
||
| Requirement | How it is met |
|
||
|-------------|---------------|
|
||
| Virtual files with read/write/unload | `VirtualFile` implements `write`, `read` and `unload`; `VirtualFileSystem` manages them. |
|
||
| Unload functionality | `VirtualFile.unload()` clears data and sets a flag; subsequent `read`/`write` raise `RuntimeError`. |
|
||
| Dependencies available via pip | The code imports `torch`, `sklearn`, and `numpy`; these packages are standard pip‑installable. |
|
||
| Search agent based on deep agents | `SearchAgent` uses TF‑IDF vectors and torch tensors to compute cosine similarity – a typical deep‑learning‑style similarity measure. |
|
||
| Integration with VFS | `SearchAgent.search()` obtains a file via `vfs.get_file()` and operates on its content. |
|
||
|
||
**Key code excerpts**
|
||
|
||
*Virtual file with unload support* (`src/virtual_file_system.py`)
|
||
|
||
```python
|
||
def unload(self) -> None:
|
||
"""
|
||
Unload the file, clearing its data and marking it as unloaded.
|
||
"""
|
||
self._data = b''
|
||
self._unloaded = True
|
||
```
|
||
|
||
*File creation in the VFS* (`src/virtual_file_system.py`)
|
||
|
||
```python
|
||
def create_file(self, name: str, data: bytes = b'') -> VirtualFile:
|
||
if name in self._files:
|
||
raise ValueError(f"File '{name}' already exists.")
|
||
vf = VirtualFile(name, data)
|
||
self._files[name] = vf
|
||
return vf
|
||
```
|
||
|
||
*Search agent using torch and sklearn* (`src/main.py`)
|
||
|
||
```python
|
||
vectorizer = TfidfVectorizer()
|
||
doc_vectors = vectorizer.fit_transform(lines).toarray()
|
||
query_vec = vectorizer.transform([query]).toarray()
|
||
|
||
doc_tensors = torch.tensor(doc_vectors, dtype=torch.float32)
|
||
query_tensor = torch.tensor(query_vec, dtype=torch.float32)
|
||
```
|
||
|
||
**Honest limitations**
|
||
|
||
- The VFS is purely in‑memory; files are lost when the process exits.
|
||
- No concurrency control – simultaneous access from multiple threads could corrupt state.
|
||
- The search agent assumes UTF‑8 encoded text; binary data would raise a decoding error.
|
||
- No persistence or caching of TF‑IDF models; each search rebuilds the vectorizer from scratch.
|
||
|
||
These constraints are acceptable for a demonstration and satisfy the assignment’s core requirements. |