Skip to content

Commit

Permalink
Merge pull request #56 from DuanxinCao/feature-tairvector
Browse files Browse the repository at this point in the history
feat: add new data structure TairVector
  • Loading branch information
yangbodong22011 authored Dec 5, 2022
2 parents 60562cd + 282c0d4 commit f7c5425
Show file tree
Hide file tree
Showing 7 changed files with 902 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tair-py is a Python client of [Tair](https://www.alibabacloud.com/help/en/apsara
- [TairGis](https://www.alibabacloud.com/help/en/apsaradb-for-redis/latest/tairgis-commands), allowing you to query points, linestrings, and polygons. (Coming soon)
- [TairTs](https://www.alibabacloud.com/help/en/apsaradb-for-redis/latest/tairts-commands), is a time series data structure that is developed on top of Redis modules. (Coming soon)
- [TairCpc](https://www.alibabacloud.com/help/en/apsaradb-for-redis/latest/taircpc-commands), is a data structure developed based on the compressed probability counting (CPC) sketch. (Coming soon)
- [TairVector](https://www.alibabacloud.com/help/en/apsaradb-for-redis/latest/tairvector), is a self-developed data structure that provides high-performance real-time storage and retrieval of vectors. (Coming soon)

## Install

Expand Down
1 change: 1 addition & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [TairDoc](https://help.aliyun.com/document_detail/145940.html), 支持存储`JSON`类型。(待开源)
- [TairTs](https://help.aliyun.com/document_detail/408954.html), 时序数据结构,提供低时延、高并发的内存读写访问。(待开源)
- [TairCpc](https://help.aliyun.com/document_detail/410587.html), 基于CPC(Compressed Probability Counting)压缩算法开发的数据结构,支持仅占用很小的内存空间对采样数据进行高性能计算。(待开源)
- [TairVector](https://help.aliyun.com/document_detail/457193.html),提供高性能、实时,集存储、检索于一体的向量数据库服务。(待开源)

## 安装

Expand Down
36 changes: 36 additions & 0 deletions examples/tair_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
from conf_examples import get_tair
from tair import ResponseError

# create an index
# @param index_name the name of index
# @param dims the dimension of vector
# @return success: True, fail: False.
def create_index(index_name: str, dims: str):
try:
tair = get_tair()
index_params = {
"M": 32,
"ef_construct": 200,
}
#index_params the params of index
return tair.tvs_create_index(index_name, dims,**index_params)
except ResponseError as e:
print(e)
return None

# delete an index
# @param index_name the name of index
# @return success: True, fail: False.
def delete_index(index_name: str):
try:
tair = get_tair()
return tair.tvs_del_index(index_name)
except ResponseError as e:
print(e)
return False


if __name__ == "__main__":
create_index("test",4)
delete_index("test")
3 changes: 3 additions & 0 deletions tair/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from tair.tairstring import ExcasResult, ExgetResult
from tair.tairts import Aggregation, TairTsSkeyItem
from tair.tairzset import TairZsetItem
from tair.tairvector import TairVectorScanResult, TairVectorIndex

__all__ = [
"Aggregation",
Expand Down Expand Up @@ -54,4 +55,6 @@
"TairError",
"TimeoutError",
"WatchError",
"TairVectorScanResult",
"TairVectorIndex",
]
21 changes: 21 additions & 0 deletions tair/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from redis import Redis
from redis.asyncio import Redis as AsyncRedis
from redis.client import bool_ok, int_or_none

from tair.tairbloom import TairBloomCommands
from tair.taircpc import CpcUpdate2judResult, TairCpcCommands
Expand All @@ -26,6 +27,14 @@
)
from tair.tairts import TairTsCommands
from tair.tairzset import TairZsetCommands, parse_tair_zset_items
from tair.tairvector import (
TairVectorCommands,
parse_tvs_get_index_result,
parse_tvs_get_result,
parse_tvs_search_result,
parse_tvs_msearch_result,
parse_tvs_hmget_result,
)


class TairCommands(
Expand All @@ -39,6 +48,7 @@ class TairCommands(
TairDocCommands,
TairTsCommands,
TairCpcCommands,
TairVectorCommands,
):
pass

Expand Down Expand Up @@ -132,6 +142,17 @@ def bool_ok(resp) -> bool:
"CPC.ARRAY.UPDATE2JUD": lambda resp: CpcUpdate2judResult(
float(resp[0].decode()), float(resp[1].decode())
),
# TairVector
"TVS.CREATEINDEX":bool_ok,
"TVS.GETINDEX": parse_tvs_get_index_result,
"TVS.DELINDEX": int_or_none,
"TVS.HSET": int_or_none,
"TVS.DEL": int_or_none,
"TVS.HDEL": int_or_none,
"TVS.HGETALL": parse_tvs_get_result,
"TVS.HMGET":parse_tvs_hmget_result,
"TVS.KNNSEARCH": parse_tvs_search_result,
"TVS.MKNNSEARCH": parse_tvs_msearch_result,
}


Expand Down
Loading

0 comments on commit f7c5425

Please sign in to comment.