Last active
December 25, 2025 05:00
-
-
Save kuc-arc-f/ed6abc2442c50859975125e0e04bbe38 to your computer and use it in GitHub Desktop.
python , Qdrant example
This file contains hidden or 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 import QdrantClient | |
| from qdrant_client.models import PointStruct | |
| import random | |
| client = QdrantClient( | |
| url="http://localhost:6333" | |
| ) | |
| points = [ | |
| PointStruct( | |
| id=1, | |
| vector=[0.1, 0.2, 0.3], | |
| payload={ | |
| "title": "テストデータ", | |
| "category": "sample" | |
| } | |
| ) | |
| ] | |
| client.upsert( | |
| collection_name="sample_collection", | |
| points=points | |
| ) | |
This file contains hidden or 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 import QdrantClient | |
| COLLE_NAME="sample_collection" | |
| # 1. クライアントの初期化(ローカルの場合) | |
| client = QdrantClient("localhost", port=6333) | |
| # 2. 指定した名前のコレクションを削除 | |
| collection_name = COLLE_NAME | |
| response = client.delete_collection(collection_name=collection_name) | |
| # 結果の確認 | |
| if response: | |
| print(f"コレクション '{collection_name}' を削除しました。") | |
| else: | |
| print(f"コレクション '{collection_name}' の削除に失敗したか、存在しません。") |
This file contains hidden or 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 import QdrantClient | |
| from qdrant_client.models import PointStruct | |
| import random | |
| COLLE_NAME="sample_collection" | |
| EMBED_SIZE=3 | |
| #EMBED_SIZE=1536 | |
| client = QdrantClient( | |
| url="http://localhost:6333" | |
| ) | |
| client.recreate_collection( | |
| collection_name=COLLE_NAME, | |
| vectors_config={ | |
| "size": EMBED_SIZE, | |
| "distance": "Cosine", # Cosine / Dot / Euclid | |
| } | |
| ) |
This file contains hidden or 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 import QdrantClient | |
| from qdrant_client.models import PointStruct | |
| import random | |
| COLLE_NAME="sample_collection" | |
| client = QdrantClient( | |
| url="http://localhost:6333" | |
| ) | |
| search_result = client.query_points( | |
| collection_name=COLLE_NAME, | |
| query=[0.1, 0.2, 0.3], # 生成したEmbedding(ベクトル) | |
| limit=5, # 上位5件を取得 | |
| #with_payload=True # メタデータも一緒に取得 | |
| ) | |
| for hit in search_result.points: | |
| print(f"ID: {hit.id}, Data: {hit.payload}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment