Spaces:
Sleeping
Sleeping
README
Browse files- indexing/README.md +48 -0
indexing/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# indexing
|
| 2 |
+
|
| 3 |
+
Local semantic search over a folder of text + images. Two FAISS indexes, queried per modality.
|
| 4 |
+
|
| 5 |
+
## Install
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
pip install -r requirements.txt
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## Build the index
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
python index.py /path/to/folder
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
Writes `index_data/text.faiss`, `index_data/image.faiss`, and matching `*_meta.json`.
|
| 18 |
+
|
| 19 |
+
## Query (CLI)
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
python query.py "your query" # all modalities
|
| 23 |
+
python query.py "your query" 10 # top_k = 10
|
| 24 |
+
python query.py "your query" -m text # text only
|
| 25 |
+
python query.py "your query" -m image # image only
|
| 26 |
+
python query.py "your query" -m text,image
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Query (Python)
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from searchers import SEARCHERS
|
| 33 |
+
|
| 34 |
+
SEARCHERS["text"]("your query", top_k=5) # -> [(score, path), ...]
|
| 35 |
+
SEARCHERS["image"]("your query", top_k=5)
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Add a modality
|
| 39 |
+
|
| 40 |
+
1. Create `searchers/<name>.py` exposing `search_<name>(query: str, top_k: int) -> list[tuple[float, str]]`.
|
| 41 |
+
2. Register it in `searchers/__init__.py`:
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from .audio import search_audio
|
| 45 |
+
SEARCHERS["audio"] = search_audio
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
It's then available in both the CLI (`-m audio`) and the `SEARCHERS` mapping.
|