diff --git a/README.md b/README.md index 93c2fcf..4e708c7 100644 --- a/README.md +++ b/README.md @@ -121,12 +121,14 @@ res = index.delete("id1") index.reset() ``` -### Index Stats +### Index Info ```python -stats = index.stats() -# stats.vector_count: total number of vectors in the index -# stats.pending_vector_count: total number of vectors waiting to be indexed -# stats.index_size: total size of the index on disk in bytes +info = index.info() +# info.vector_count: total number of vectors in the index +# info.pending_vector_count: total number of vectors waiting to be indexed +# info.index_size: total size of the index on disk in bytes +# info.dimension: how many dimensions the index has +# info.similarity_function: similarity function chosen for the index ``` # Contributing diff --git a/pyproject.toml b/pyproject.toml index 4422682..fff3164 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "upstash-vector" -version = "0.1.6" +version = "0.2.0" description = "Serverless Vector SDK from Upstash" license = "MIT" authors = ["Upstash "] diff --git a/tests/core/test_info.py b/tests/core/test_info.py new file mode 100644 index 0000000..5f9b6ce --- /dev/null +++ b/tests/core/test_info.py @@ -0,0 +1,37 @@ +import pytest + +from tests import assert_eventually, assert_eventually_async +from upstash_vector import Index, AsyncIndex + + +def test_info(index: Index): + info = index.info() + + assert info.vector_count == 0 + assert info.pending_vector_count == 0 + assert info.dimension == 2 + assert info.similarity_function == "COSINE" + + index.upsert([{"id": "foo", "vector": [0, 1]}]) + + def assertion(): + assert index.info().vector_count == 1 + + assert_eventually(assertion) + + +@pytest.mark.asyncio +async def test_info_async(async_index: AsyncIndex): + info = await async_index.info() + + assert info.vector_count == 0 + assert info.pending_vector_count == 0 + assert info.dimension == 2 + assert info.similarity_function == "COSINE" + + await async_index.upsert([{"id": "foo", "vector": [0, 1]}]) + + async def assertion(): + assert (await async_index.info()).vector_count == 1 + + await assert_eventually_async(assertion) diff --git a/tests/core/test_stats.py b/tests/core/test_stats.py deleted file mode 100644 index 39a4612..0000000 --- a/tests/core/test_stats.py +++ /dev/null @@ -1,33 +0,0 @@ -import pytest - -from tests import assert_eventually, assert_eventually_async -from upstash_vector import Index, AsyncIndex - - -def test_stats(index: Index): - stats = index.stats() - - assert stats.vector_count == 0 - assert stats.pending_vector_count == 0 - - index.upsert([{"id": "foo", "vector": [0, 1]}]) - - def assertion(): - assert index.stats().vector_count == 1 - - assert_eventually(assertion) - - -@pytest.mark.asyncio -async def test_stats_async(async_index: AsyncIndex): - stats = await async_index.stats() - - assert stats.vector_count == 0 - assert stats.pending_vector_count == 0 - - await async_index.upsert([{"id": "foo", "vector": [0, 1]}]) - - async def assertion(): - assert (await async_index.stats()).vector_count == 1 - - await assert_eventually_async(assertion) diff --git a/upstash_vector/__init__.py b/upstash_vector/__init__.py index f2573e8..536d3aa 100644 --- a/upstash_vector/__init__.py +++ b/upstash_vector/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.6" +__version__ = "0.2.0" from upstash_vector.client import Index, AsyncIndex from upstash_vector.types import Vector diff --git a/upstash_vector/core/index_operations.py b/upstash_vector/core/index_operations.py index 6024906..1821d8a 100644 --- a/upstash_vector/core/index_operations.py +++ b/upstash_vector/core/index_operations.py @@ -6,7 +6,7 @@ from upstash_vector.types import ( DeleteResult, RangeResult, - StatsResult, + InfoResult, SupportsToList, Vector, FetchResult, @@ -21,7 +21,7 @@ RESET_PATH = "/reset" RANGE_PATH = "/range" FETCH_PATH = "/fetch" -STATS_PATH = "/stats" +INFO_PATH = "/info" class IndexOperations: @@ -213,16 +213,18 @@ def fetch( for vector in self._execute_request(payload=payload, path=FETCH_PATH) ] - def stats(self) -> StatsResult: + def info(self) -> InfoResult: """ - Returns the index statistics, including: + Returns the index info, including: * total number of vectors * total number of vectors waiting to be indexed * total size of the index on disk in bytes + * dimension count for the index + * similarity function selected for the index """ - return StatsResult._from_json( - self._execute_request(payload=None, path=STATS_PATH) + return InfoResult._from_json( + self._execute_request(payload=None, path=INFO_PATH) ) @@ -420,14 +422,16 @@ async def fetch( ) ] - async def stats(self) -> StatsResult: + async def info(self) -> InfoResult: """ - Returns the index statistics asynchronously, including: + Returns the index info asynchronously, including: * total number of vectors * total number of vectors waiting to be indexed * total size of the index on disk in bytes + * dimension count for the index + * similarity function selected for the index """ - return StatsResult._from_json( - await self._execute_request_async(payload=None, path=STATS_PATH) + return InfoResult._from_json( + await self._execute_request_async(payload=None, path=INFO_PATH) ) diff --git a/upstash_vector/types.py b/upstash_vector/types.py index b1dc42f..f51be68 100644 --- a/upstash_vector/types.py +++ b/upstash_vector/types.py @@ -69,15 +69,20 @@ def _from_json(cls, obj: dict) -> "RangeResult": @dataclass -class StatsResult: +class InfoResult: vector_count: int pending_vector_count: int index_size: int + dimension: int + similarity_function: str @classmethod - def _from_json(cls, obj: dict) -> "StatsResult": + def _from_json(cls, obj: dict) -> "InfoResult": + print(obj) return cls( vector_count=obj["vectorCount"], pending_vector_count=obj["pendingVectorCount"], index_size=obj["indexSize"], + dimension=obj["dimension"], + similarity_function=obj["similarityFunction"], )