Skip to content

Commit fd7e303

Browse files
authored
Update the version to 0.1.29 (#406)
Signed-off-by: SimFG <[email protected]>
1 parent c274d83 commit fd7e303

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

docs/release_note.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ To read the following content, you need to understand the basic use of GPTCache,
55
- [Readme doc](https://github.com/zilliztech/GPTCache)
66
- [Usage doc](https://github.com/zilliztech/GPTCache/blob/main/docs/usage.md)
77

8+
## v0.1.29 (2023.6.2)
9+
10+
1. Improve the GPTCache server by using FASTAPI
11+
12+
**NOTE**: The api struct has been optimized, details: [Use GPTCache server](https://github.com/zilliztech/GPTCache/blob/dev/docs/usage.md#use-gptcache-server)
13+
14+
2. Add the usearch vector store
15+
16+
```python
17+
from gptcache.manager import manager_factory
18+
19+
data_manager = manager_factory("sqlite,usearch", vector_params={"dimension": 10})
20+
```
21+
822
## v0.1.28 (2023.5.29)
923
To handle a large prompt, there are currently two options available:
1024

gptcache/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""gptcache version"""
2-
__version__ = "0.1.28"
2+
__version__ = "0.1.29"
33

44
from gptcache.config import Config
55
from gptcache.core import Cache

gptcache/manager/vector_data/manager.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
"params": {"M": 8, "efConstruction": 64},
1717
}
1818

19-
PGVECTOR_URL="postgresql://postgres:postgres@localhost:5432/postgres"
20-
PGVECTOR_INDEX_PARAMS = {
21-
"index_type": "L2",
22-
"params": {"lists": 100, "probes": 10}
23-
}
19+
PGVECTOR_URL = "postgresql://postgres:postgres@localhost:5432/postgres"
20+
PGVECTOR_INDEX_PARAMS = {"index_type": "L2", "params": {"lists": 100, "probes": 10}}
2421

2522
COLLECTION_NAME = "gptcache"
2623

@@ -169,6 +166,7 @@ def get(name, **kwargs):
169166
)
170167
elif name == "pgvector":
171168
from gptcache.manager.vector_data.pgvector import PGVector
169+
172170
dimension = kwargs.get("dimension", DIMENSION)
173171
url = kwargs.get("url", PGVECTOR_URL)
174172
collection_name = kwargs.get("collection_name", COLLECTION_NAME)
@@ -178,13 +176,27 @@ def get(name, **kwargs):
178176
top_k=top_k,
179177
url=url,
180178
collection_name=collection_name,
181-
index_params=index_params
179+
index_params=index_params,
182180
)
183181
elif name == "docarray":
184182
from gptcache.manager.vector_data.docarray_index import DocArrayIndex
185183

186184
index_path = kwargs.pop("index_path", "./docarray_index.bin")
187185
vector_base = DocArrayIndex(index_file_path=index_path, top_k=top_k)
186+
elif name == "usearch":
187+
from gptcache.manager.vector_data.usearch import USearch
188+
189+
dimension = kwargs.get("dimension", DIMENSION)
190+
index_path = kwargs.pop("index_path", "./index.usearch")
191+
metric = kwargs.get("metric", "cos")
192+
dtype = kwargs.get("dtype", "f32")
193+
vector_base = USearch(
194+
index_file_path=index_path,
195+
dimension=dimension,
196+
top_k=top_k,
197+
metric=metric,
198+
dtype=dtype,
199+
)
188200
else:
189201
raise NotFoundError("vector store", name)
190202
return vector_base

gptcache/manager/vector_data/usearch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from gptcache.utils import import_usearch
88

99
import_usearch()
10+
1011
from usearch.index import Index # pylint: disable=C0413
1112

1213

@@ -33,11 +34,11 @@ class USearch(VectorBase):
3334

3435
def __init__(
3536
self,
36-
index_file_path: str = 'index.usearch',
37+
index_file_path: str = "index.usearch",
3738
dimension: int = 64,
3839
top_k: int = 1,
39-
metric: str = 'cos',
40-
dtype: str = 'f32',
40+
metric: str = "cos",
41+
dtype: str = "f32",
4142
connectivity: int = 16,
4243
expansion_add: int = 128,
4344
expansion_search: int = 64,
@@ -57,16 +58,15 @@ def __init__(
5758
self._index.load(self._index_file_path)
5859

5960
def mul_add(self, datas: List[VectorData]):
60-
data_array, id_array = map(
61-
list, zip(*((data.data, data.id) for data in datas)))
62-
np_data = np.array(data_array).astype('float32')
61+
data_array, id_array = map(list, zip(*((data.data, data.id) for data in datas)))
62+
np_data = np.array(data_array).astype("float32")
6363
ids = np.array(id_array, dtype=np.longlong)
6464
self._index.add(ids, np_data)
6565

6666
def search(self, data: np.ndarray, top_k: int = -1):
6767
if top_k == -1:
6868
top_k = self._top_k
69-
np_data = np.array(data).astype('float32').reshape(1, -1)
69+
np_data = np.array(data).astype("float32").reshape(1, -1)
7070
ids, dist, _ = self._index.search(np_data, top_k)
7171
return list(zip(dist[0], ids[0]))
7272

tests/unit_tests/manager/test_usearch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import unittest
2+
23
import numpy as np
34

4-
from gptcache.manager.vector_data.usearch import USearch
5+
from gptcache.manager.vector_data import VectorBase
56
from gptcache.manager.vector_data.base import VectorData
67

78

@@ -11,7 +12,8 @@ def test_normal(self):
1112
dim = 512
1213
top_k = 10
1314

14-
db = USearch(
15+
db = VectorBase(
16+
"usearch",
1517
index_file_path='./index.usearch',
1618
dimension=dim,
1719
top_k=top_k,

0 commit comments

Comments
 (0)