-
-
Save nishio/111f11e078dd68768f5904ea879abe2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qdrant_client.http.models import PointStruct | |
from qdrant_client import QdrantClient | |
from qdrant_client.http.models import Distance, VectorParams | |
from qdrant_client.http.models import Filter, FieldCondition, MatchValue | |
import pprint | |
client = QdrantClient("localhost", port=6333) | |
client.recreate_collection( | |
collection_name="test_collection", | |
vectors_config=VectorParams(size=4, distance=Distance.DOT), | |
) | |
operation_info = client.upsert( | |
collection_name="test_collection", | |
wait=True, | |
points=[ | |
PointStruct( | |
id=1, | |
vector=[0.05, 0.61, 0.76, 0.74], | |
payload={ | |
"city": "Berlin", | |
"text": "フルテキストインデックスのトークナイザー、説明を見る限りだと日本語に対してまともに機能するか疑わしい", | |
}, | |
), | |
PointStruct( | |
id=2, | |
vector=[0.19, 0.81, 0.75, 0.11], | |
payload={"city": ["Berlin", "London"], "text": "foo bar baz"}, | |
), | |
PointStruct( | |
id=3, | |
vector=[0.36, 0.55, 0.47, 0.94], | |
payload={ | |
"city": ["Berlin", "Moscow"], | |
"text": "フルテキスト インデックス の トークナイザー、 説明を見る限りだと 日本語に対して まともに機能するか疑わしい", | |
}, | |
), | |
PointStruct( | |
id=4, | |
vector=[0.18, 0.01, 0.85, 0.80], | |
payload={"city": ["London", "Moscow"]}, | |
), | |
PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"count": [0]}), | |
PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44]), | |
], | |
) | |
# search_result = client.search( | |
# collection_name="test_collection", query_vector=[0.2, 0.1, 0.9, 0.7], limit=3 | |
# ) | |
# print(search_result) | |
# search_result = client.search( | |
# collection_name="test_collection", | |
# query_vector=[0.2, 0.1, 0.9, 0.7], | |
# query_filter=Filter( | |
# must=[FieldCondition(key="city", match=MatchValue(value="London"))] | |
# ), | |
# limit=3, | |
# ) | |
# print(search_result) | |
# search_result = client.search( | |
# collection_name="test_collection", | |
# query_vector=[0.2, 0.1, 0.9, 0.7], | |
# query_filter=Filter(must=[FieldCondition(key="text", match={"text": "foo"})]), | |
# limit=3, | |
# ) | |
# print(search_result) | |
# search_result = client.search( | |
# collection_name="test_collection", | |
# query_vector=[0.2, 0.1, 0.9, 0.7], | |
# query_filter=Filter(must=[FieldCondition(key="text", match={"text": "ルテ"})]), | |
# limit=3, | |
# ) | |
# pprint.pprint(search_result) | |
# """ | |
# [ScoredPoint(id=1, version=0, score=1.273, payload={'city': 'Berlin', 'text': 'フルテキストインデックスのトークナイザー、説明を見る限りだと日本語に対してまともに機能するか疑わしい'}, vector=None), | |
# ScoredPoint(id=3, version=0, score=1.208, payload={'city': ['Berlin', 'Moscow'], 'text': 'フルテキスト インデックス の トークナイザー、 説明を見る限りだと 日本語に対して まともに機能するか疑わしい'}, vector=None)] | |
# """ | |
search_result = client.search( | |
collection_name="test_collection", | |
query_vector=[0.2, 0.1, 0.9, 0.7], | |
query_filter=Filter(must=[FieldCondition(key="text", match={"text": "本"})]), | |
limit=3, | |
) | |
pprint.pprint(search_result) | |
""" | |
[ScoredPoint(id=1, version=0, score=1.273, payload={'city': 'Berlin', 'text': 'フルテキストインデックスのトークナイザー、説明を見る限りだと日本語に対してまともに機能するか疑わしい'}, vector=None), | |
ScoredPoint(id=3, version=0, score=1.208, payload={'city': ['Berlin', 'Moscow'], 'text': 'フルテキスト インデックス の トークナイザー、 説明を見る限りだと 日本語に対して まともに機能するか疑わしい'}, vector=None)] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment