This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathexport_qdrant.py
More file actions
executable file
·100 lines (79 loc) · 3.03 KB
/
Copy pathexport_qdrant.py
File metadata and controls
executable file
·100 lines (79 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""
Export script for Qdrant vector database.
This script exports a Qdrant collection to a portable file format.
"""
import argparse
import pickle
from qdrant_client import QdrantClient
__author__ = "Lâm Quang Trí"
__copyright__ = "Copyright 2025, Lâm Quang Trí"
__credits__ = ["Lâm Quang Trí"]
__maintainer__ = "Lâm Quang Trí"
__email__ = "quangtri.lam.9@gmail.com"
__status__ = "Development"
def export_qdrant_collection(
collection_name, output_file="qdrant_export.pkl", host="localhost", port=6333
):
"""Export a Qdrant collection to a portable file format."""
print(f"Connecting to Qdrant at {host}:{port}...")
client = QdrantClient(host=host, port=port)
# Check if collection exists
collections = client.get_collections().collections
collection_names = [c.name for c in collections]
if collection_name not in collection_names:
raise ValueError(f"Collection '{collection_name}' does not exist")
# Get collection info
print(f"Getting collection info for '{collection_name}'...")
collection_info = client.get_collection(collection_name=collection_name)
# Get all points with their vectors and payloads
# We'll retrieve in batches to handle large collections
limit = 1000
offset = 0
all_points = []
print("Retrieving points from collection...")
while True:
points = client.scroll(
collection_name=collection_name,
limit=limit,
offset=offset,
with_vectors=True,
with_payload=True,
)[0]
if not points:
break
all_points.extend(points)
offset += limit
print(f"Retrieved {len(all_points)} points so far...")
if len(points) < limit:
break
# Create the export data structure
export_data = {
"collection_info": {
"name": collection_name,
"vector_size": collection_info.config.params.vectors.size,
"vector_distance": collection_info.config.params.vectors.distance.name,
},
"points": [
{"id": point.id, "vector": point.vector, "payload": point.payload}
for point in all_points
],
}
# Save to file
print(f"Saving {len(all_points)} points to {output_file}...")
with open(output_file, "wb") as f:
pickle.dump(export_data, f)
print(f"Export complete. Saved {len(all_points)} points to {output_file}")
return output_file
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Export Qdrant collection to a portable file"
)
parser.add_argument("collection_name", help="Name of the collection to export")
parser.add_argument(
"--output", default="qdrant_export.pkl", help="Output file path"
)
parser.add_argument("--host", default="localhost", help="Qdrant host")
parser.add_argument("--port", type=int, default=6333, help="Qdrant port")
args = parser.parse_args()
export_qdrant_collection(args.collection_name, args.output, args.host, args.port)