diff --git a/examples/face_recognition/README.md b/examples/face_recognition/README.md index 5d313dd42..9a31512eb 100644 --- a/examples/face_recognition/README.md +++ b/examples/face_recognition/README.md @@ -21,7 +21,12 @@ We appreciate a star ⭐ at [CocoIndex Github](https://github.com/cocoindex-io/c 1. [Install Postgres](https://cocoindex.io/docs/getting_started/installation#-install-postgres) if you don't have one. -2. dependencies: +2. Install Qdrant + ```bash + docker run -d -p 6334:6334 -p 6333:6333 qdrant/qdrant + ``` + +3. Install dependencies: ```bash pip install -e . diff --git a/examples/face_recognition/main.py b/examples/face_recognition/main.py index d7f04840b..caf9b88c7 100644 --- a/examples/face_recognition/main.py +++ b/examples/face_recognition/main.py @@ -1,12 +1,15 @@ import cocoindex -import io import dataclasses import datetime -import typing +import io +import os import face_recognition -from PIL import Image import numpy as np +from PIL import Image + +QDRANT_URL = os.getenv("QDRANT_URL", "http://localhost:6334/") +QDRANT_COLLECTION = "face_embeddings" @dataclasses.dataclass @@ -90,7 +93,7 @@ def face_recognition_flow( flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope ) -> None: """ - Define an example flow that embeds files into a vector database. + Define an example flow that embeds files into Qdrant vector database. """ data_scope["images"] = flow_builder.add_source( cocoindex.sources.LocalFile(path="images", binary=True), @@ -108,13 +111,14 @@ def face_recognition_flow( # Collect embeddings face_embeddings.collect( + id=cocoindex.GeneratedField.UUID, filename=image["filename"], rect=face["rect"], embedding=face["embedding"], ) face_embeddings.export( - "face_embeddings", - cocoindex.targets.Postgres(), - primary_key_fields=["filename", "rect"], + QDRANT_COLLECTION, + cocoindex.targets.Qdrant(collection_name=QDRANT_COLLECTION), + primary_key_fields=["id"], )