Skip to content

Commit 3e7e19a

Browse files
authored
Merge pull request #53 from iryna-kondr/fix_annoy
Make annoy an optional dependency
2 parents facbef2 + 950b8ca commit 3e7e19a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ Note: as the model is not being re-trained, but uses the training data during in
203203

204204
### Dynamic Few-Shot Text Classification
205205

206+
*To use this feature, you need to install `annoy` library:*
207+
208+
```bash
209+
pip install scikit-llm[annoy]
210+
```
211+
206212
`DynamicFewShotGPTClassifier` dynamically selects N samples per class to include in the prompt. This allows the few-shot classifier to scale to datasets that are too large for the standard context window of LLMs.
207213

208214
*How does it work?*

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ dependencies = [
88
"pandas>=1.5.0",
99
"openai>=0.27.0",
1010
"tqdm>=4.60.0",
11-
"annoy>=1.17.2",
1211
"google-cloud-aiplatform>=1.27.0"
1312
]
1413
name = "scikit-llm"
15-
version = "0.3.3"
14+
version = "0.3.4"
1615
authors = [
1716
{ name="Oleg Kostromin", email="[email protected]" },
1817
{ name="Iryna Kondrashchenko", email="[email protected]" },
@@ -29,6 +28,7 @@ classifiers = [
2928

3029
[project.optional-dependencies]
3130
gpt4all = ["gpt4all>=1.0.0"]
31+
annoy = ["annoy>=1.17.2"]
3232

3333
[tool.ruff]
3434
select = [

skllm/memory/_annoy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import tempfile
33
from typing import Any, List
44

5-
from annoy import AnnoyIndex
5+
try:
6+
from annoy import AnnoyIndex
7+
except (ImportError, ModuleNotFoundError):
8+
AnnoyIndex = None
9+
610
from numpy import ndarray
711

812
from skllm.memory.base import _BaseMemoryIndex
@@ -20,6 +24,10 @@ class AnnoyMemoryIndex(_BaseMemoryIndex):
2024
"""
2125

2226
def __init__(self, dim: int, metric: str = "euclidean", **kwargs: Any) -> None:
27+
if AnnoyIndex is None:
28+
raise ImportError(
29+
"Annoy is not installed. Please install annoy by running `pip install scikit-llm[annoy]`."
30+
)
2331
self._index = AnnoyIndex(dim, metric)
2432
self.metric = metric
2533
self.dim = dim

0 commit comments

Comments
 (0)