Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the version to 0.1.29 #406

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/release_note.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ To read the following content, you need to understand the basic use of GPTCache,
- [Readme doc](https://github.com/zilliztech/GPTCache)
- [Usage doc](https://github.com/zilliztech/GPTCache/blob/main/docs/usage.md)

## v0.1.29 (2023.6.2)

1. Improve the GPTCache server by using FASTAPI

**NOTE**: The api struct has been optimized, details: [Use GPTCache server](https://github.com/zilliztech/GPTCache/blob/dev/docs/usage.md#use-gptcache-server)

2. Add the usearch vector store

```python
from gptcache.manager import manager_factory

data_manager = manager_factory("sqlite,usearch", vector_params={"dimension": 10})
```

## v0.1.28 (2023.5.29)
To handle a large prompt, there are currently two options available:

Expand Down
2 changes: 1 addition & 1 deletion gptcache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""gptcache version"""
__version__ = "0.1.28"
__version__ = "0.1.29"

from gptcache.config import Config
from gptcache.core import Cache
Expand Down
24 changes: 18 additions & 6 deletions gptcache/manager/vector_data/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
"params": {"M": 8, "efConstruction": 64},
}

PGVECTOR_URL="postgresql://postgres:postgres@localhost:5432/postgres"
PGVECTOR_INDEX_PARAMS = {
"index_type": "L2",
"params": {"lists": 100, "probes": 10}
}
PGVECTOR_URL = "postgresql://postgres:postgres@localhost:5432/postgres"
PGVECTOR_INDEX_PARAMS = {"index_type": "L2", "params": {"lists": 100, "probes": 10}}

COLLECTION_NAME = "gptcache"

Expand Down Expand Up @@ -169,6 +166,7 @@ def get(name, **kwargs):
)
elif name == "pgvector":
from gptcache.manager.vector_data.pgvector import PGVector

dimension = kwargs.get("dimension", DIMENSION)
url = kwargs.get("url", PGVECTOR_URL)
collection_name = kwargs.get("collection_name", COLLECTION_NAME)
Expand All @@ -178,13 +176,27 @@ def get(name, **kwargs):
top_k=top_k,
url=url,
collection_name=collection_name,
index_params=index_params
index_params=index_params,
)
elif name == "docarray":
from gptcache.manager.vector_data.docarray_index import DocArrayIndex

index_path = kwargs.pop("index_path", "./docarray_index.bin")
vector_base = DocArrayIndex(index_file_path=index_path, top_k=top_k)
elif name == "usearch":
from gptcache.manager.vector_data.usearch import USearch

dimension = kwargs.get("dimension", DIMENSION)
index_path = kwargs.pop("index_path", "./index.usearch")
metric = kwargs.get("metric", "cos")
dtype = kwargs.get("dtype", "f32")
vector_base = USearch(
index_file_path=index_path,
dimension=dimension,
top_k=top_k,
metric=metric,
dtype=dtype,
)
else:
raise NotFoundError("vector store", name)
return vector_base
14 changes: 7 additions & 7 deletions gptcache/manager/vector_data/usearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from gptcache.utils import import_usearch

import_usearch()

from usearch.index import Index # pylint: disable=C0413


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

def __init__(
self,
index_file_path: str = 'index.usearch',
index_file_path: str = "index.usearch",
dimension: int = 64,
top_k: int = 1,
metric: str = 'cos',
dtype: str = 'f32',
metric: str = "cos",
dtype: str = "f32",
connectivity: int = 16,
expansion_add: int = 128,
expansion_search: int = 64,
Expand All @@ -57,16 +58,15 @@ def __init__(
self._index.load(self._index_file_path)

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

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

Expand Down
6 changes: 4 additions & 2 deletions tests/unit_tests/manager/test_usearch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest

import numpy as np

from gptcache.manager.vector_data.usearch import USearch
from gptcache.manager.vector_data import VectorBase
from gptcache.manager.vector_data.base import VectorData


Expand All @@ -11,7 +12,8 @@ def test_normal(self):
dim = 512
top_k = 10

db = USearch(
db = VectorBase(
"usearch",
index_file_path='./index.usearch',
dimension=dim,
top_k=top_k,
Expand Down