Complete Qdrant Tutorial: Vector Database for AI Applications

# Tutorial Lengkap Qdrant: Vector Database untuk Aplikasi AI Qdrant adalah vector database performa tinggi yang dirancang untuk similarity search dan aplikasi AI. Library ini menyediakan penyimpanan...

By Ruby Abdullah · · tutorial
QdrantVector DatabaseSemantic SearchRAGPythonAI

Complete Qdrant Tutorial: Vector Database for AI Applications

Qdrant is a high-performance vector database designed for similarity search and AI applications. It provides efficient storage and retrieval of vector embeddings, making it ideal for building recommendation systems, semantic search, and RAG applications.

Why Qdrant?

Qdrant Advantages:
  • High performance: Rust-based engine for speed
  • Rich filtering: Combine vector search with metadata filters
  • Scalable: Distributed mode for large datasets
  • Easy to use: REST and gRPC APIs
  • Cloud native: Docker, Kubernetes ready

Use Cases:
  • Semantic search
  • Recommendation systems
  • RAG (Retrieval-Augmented Generation)
  • Image similarity search
  • Anomaly detection

Installation

# Python client

pip install qdrant-client

Run Qdrant with Docker

docker run -p 6333:6333 -p 6334:6334 \

-v $(pwd)/qdrantstorage:/qdrant/storage:z \

qdrant/qdrant

Verify

python -c "from qdrantclient import QdrantClient; print('Qdrant client ready')"

Quick Start

1. Connect to Qdrant

from qdrantclient import QdrantClient

Local instance

client = QdrantClient("localhost", port=6333)

In-memory (for testing)

client = QdrantClient(":memory:")

Qdrant Cloud

client = QdrantClient(

url="https://xxx-xxx.us-east-1-0.aws.cloud.qdrant.io",

apikey="your-api-key"

)

Check connection

print(client.getcollections())

2. Create Collection

from qdrantclient import QdrantClient

from qdrantclient.models import Distance, VectorParams

client = QdrantClient("localhost", port=6333)

Create collection

client.createcollection(

collectionname="mycollection",

vectorsconfig=VectorParams(size=384, distance=Distance.COSINE)

)

List collections

collections = client.getcollections()

print(collections)

3. Insert Vectors

from qdrantclient.models import PointStruct

Insert points

client.upsert(

collectionname="mycollection",

points=[

PointStruct(

id=1,

vector=[0.1, 0.2, 0.3, ...], # 384-dim vector

payload={"title": "Document 1", "category": "tech"}

),

PointStruct(

id=2,

vector=[0.4, 0.5, 0.6, ...],

payload={"title": "Document 2", "category": "science"}

)

]

)

4. Search Vectors

# Search

results = client.search(

collectionname="mycollection",

queryvector=[0.1, 0.2, 0.3, ...],

limit=5

)

for result in results:

print(f"ID: {result.id}, Score: {result.score}")

print(f"Payload: {result.payload}")

Working with Embeddings

1. Using Sentence Transformers

from qdrantclient import QdrantClient

from qdrantclient.models import Distance, VectorParams, PointStruct

from sentencetransformers import SentenceTransformer

Initialize

client = QdrantClient("localhost", port=6333)

model = SentenceTransformer("all-MiniLM-L6-v2")

Create collection

client.recreatecollection(

collectionname="documents",

vectorsconfig=VectorParams(size=384, distance=Distance.COSINE)

)

Prepare documents

documents = [

{"id": 1, "text": "Machine learning is fascinating", "category": "tech"},

{"id": 2, "text": "Natural language processing", "category": "tech"},

{"id": 3, "text": "Cooking recipes for beginners", "category": "food"},

]

Generate embeddings and insert

points = []

for doc in documents:

embedding = model.encode(doc["text"]).tolist()

points.append(PointStruct(

id=doc["id"],

vector=embedding,

payload={"text": doc["text"], "category": doc["category"]}

))

client.upsert(collectionname="documents", points=points)

Search

query = "AI and deep learning"

Related Articles

Complete LlamaIndex Tutorial: Building RAG Applications with LLMs

Tutorial Lengkap LlamaIndex: Membangun Aplikasi RAG dengan LLM LlamaIndex adalah framework data yang powerful untuk memb...

Complete ChromaDB Tutorial: Simple Vector Database for AI

Tutorial Lengkap ChromaDB: Vector Database Sederhana untuk AI ChromaDB adalah open-source vector database yang dirancang...

Weaviate: Vector Database with Integrated AI Modules

Weaviate: Database Vektor dengan AI Modules Terintegrasi Weaviate adalah database vektor open-source yang dirancang untu...

Milvus Tutorial: Distributed Vector Database for AI

Tutorial 10: Milvus - Database Vektor Terdistribusi untuk AI Daftar Isi Pendahuluan Prasyarat Arsitektur Milvus [Instala...