Spaces:
Sleeping
Sleeping
Download adsp/storage/vector_db.py from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 667 Bytes
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/storage/vector_db.py
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/adsp/storage/vector_db.py
-
curl -L -o vector_db.py https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/adsp/storage/vector_db.py
667 Bytes
| """In-memory vector database stub.""" | |
| from __future__ import annotations | |
| from collections import defaultdict | |
| from dataclasses import dataclass, field | |
| from typing import DefaultDict, List | |
| class VectorDatabase: | |
| """Stores persona documents and returns naive matches.""" | |
| _documents: DefaultDict[str, List[str]] = field(default_factory=lambda: defaultdict(list)) | |
| def upsert(self, persona_id: str, document: str) -> None: | |
| self._documents[persona_id].append(document) | |
| def search(self, persona_id: str, query: str) -> str: | |
| docs = self._documents[persona_id] | |
| if not docs: | |
| return "" | |
| return docs[-1] | |