
Security News
PyPI Expands Trusted Publishing to GitLab Self-Managed as Adoption Passes 25 Percent
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads
hologres-vector
Advanced tools
Use Hologres to store large amount of vector data and perform high speed k-nearest-neighbour search!
Table of Contents
pip install hologres-vector
from hologres_vector import HologresVector
import os
host = os.environ["HOLO_HOST"]
port = os.environ["HOLO_PORT"]
dbname = os.environ["HOLO_DBNAME"]
user = os.environ["HOLO_USER"]
password = os.environ["HOLO_PASSWORD"]
connection_string = HologresVector.connection_string_from_db_params(host, port, dbname, user, password)
建表时,需要指定向量的维数,以及表中的除向量数据、主键、json元数据以外的其他强schema列。
table_name = "test_table"
holo = HologresVector(
connection_string, # 连接信息
5, # 向量维度
table_name=table_name, # 表名
table_schema={"t": "text", "date": "timestamptz", "i": "int"},
distance_method="SquaredEuclidean", # 距离函数,推荐用默认值,也可以选择"Euclidean"或"InnerProduct"
pre_delete_table=False, # 若表已存在则先删除
)
支持强schema列 schema_datas 与一个json列 metadatas。
该接口为批量导入,内部会将输入数据切分为512行的批进行插入。
vectors = [[0,0,0,0,0], [1,1,1,1,1], [2,2,2,2,2]]
ids = ['0', '1', '2'] # primary key
schema_datas = [
{'t': 'text 0', 'date': '2023-08-02 18:30:00', 'i': 0},
{'t': 'text 1', 'date': '2023-08-02 19:30:00', 'i': 1},
{'t': 'text 2', 'date': '2023-08-02 20:30:00', 'i': 2},
]
metadatas = [
{'a': "hello"},
{'b': 123},
{},
]
holo.upsert_vectors(vectors, ids, schema_datas=schema_datas, metadatas=metadatas)
holo.query(limit=1)
[{'id': '2', 'vector': [2.0, 2.0, 2.0, 2.0, 2.0], 'metadata': {}}]
2. 近邻查询:根据向量从数据库中取最近邻
holo.search([0.1, 0.1, 0.1, 0.1, 0.1], k=2, select_columns=['t'])
[{'id': '0', 'metadata': {'a': 'hello'}, 'distance': 0.05, 't': 'text 0'},
{'id': '1', 'metadata': {'b': 123}, 'distance': 4.05, 't': 'text 1'}]
3. 融合查询:根据向量从数据库中取最近邻,并用其他列查询条件约束
holo.search([0.1, 0.1, 0.1, 0.1, 0.1], k=2, schema_data_filters={'t': 'text 1'})
[{'id': '1', 'metadata': {'b': 123}, 'distance': 4.05}]
本SDK目前默认使用根据主键id的一种插入替换策略:当插入的数据和已有数据主键相同时,用新插入的整行替换已有的行。
# 先插入一行id为3的数据
holo.upsert_vectors([[3, 3, 3, 3, 3]], [3], schema_datas=[{'t': 'old data'}])
# 再插入一行id为3的数据,下面这行会将上面的整行替换掉
holo.upsert_vectors([[-3, -3, -3, -3, -3]], [3], schema_datas=[{'t': 'new data'}])
holo.query(schema_data_filters={'id': '3'})
[{'id': '3', 'vector': [-3.0, -3.0, -3.0, -3.0, -3.0], 'metadata': {}}]
可使用与查询格式相同的filter条件来对数据进行部分删除。
holo.delete_vectors(schema_data_filters={'id': '2'})
holo.query(limit=10)
[{'id': '0', 'vector': [0.0, 0.0, 0.0, 0.0, 0.0], 'metadata': {'a': 'hello'}},
{'id': '1', 'vector': [1.0, 1.0, 1.0, 1.0, 1.0], 'metadata': {'b': 123}},
{'id': '3', 'vector': [-3.0, -3.0, -3.0, -3.0, -3.0], 'metadata': {}}]
holo.delete_vectors() # 删除全部数据
holo.query(limit=10)
hologres-vector is distributed under the terms of the MIT license.
FAQs
Unknown package
We found that hologres-vector demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.