Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:

qdrant:
container_name: qdrant_demo_qdrant
image: qdrant/qdrant:v1.7.3
image: qdrant/qdrant:latest
ports:
- "6333:6333"
- "6334:6334"
Expand Down
20 changes: 16 additions & 4 deletions qdrant_demo/init_collection_startups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import os.path
import logging
from datetime import datetime

from qdrant_client import QdrantClient, models
from tqdm import tqdm
Expand All @@ -8,42 +10,49 @@


def upload_embeddings():
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Initializing Qdrant client...")
client = QdrantClient(
url=QDRANT_URL,
api_key=QDRANT_API_KEY,
prefer_grpc=True,
)

print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Setting embedding model: {EMBEDDINGS_MODEL}")
client.set_model(EMBEDDINGS_MODEL)

payload_path = os.path.join(DATA_DIR, 'startups_demo.json')
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Loading data from file: {payload_path}")
payload = []
documents = []

with open(payload_path) as fd:
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Processing data...")
for line in fd:
obj = json.loads(line)
# Rename fields to unified schema
documents.append(obj.pop('description'))
obj["logo_url"] = obj.pop("images")
obj["homepage_url"] = obj.pop("link")
payload.append(obj)

print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Data processed: {len(documents)} documents")

print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Recreating collection: {COLLECTION_NAME}")
client.recreate_collection(
collection_name=COLLECTION_NAME,
vectors_config=client.get_fastembed_vector_params(on_disk=True),
# Quantization is optional, but it can significantly reduce the memory usage
quantization_config=models.ScalarQuantization(
scalar=models.ScalarQuantizationConfig(
type=models.ScalarType.INT8,
quantile=0.99,
always_ram=True
)
),
optimizers_config=models.OptimizersConfigDiff(
max_optimization_threads=2
)
)

# Create a payload index for text field.
# This index enables text search by the TEXT_FIELD_NAME field.
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Creating payload index for field: {TEXT_FIELD_NAME}")
client.create_payload_index(
collection_name=COLLECTION_NAME,
field_name=TEXT_FIELD_NAME,
Expand All @@ -56,13 +65,16 @@ def upload_embeddings():
)
)

print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Uploading documents to collection...")
client.add(
collection_name=COLLECTION_NAME,
documents=documents,
metadata=payload,
ids=tqdm(range(len(payload))),
parallel=0,
)

print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]} - INFO - Upload completed successfully!")


if __name__ == '__main__':
Expand Down