Trending

World technology news

→
Vector Databases 5/5: Local Qdrant and Cloudflare Architecture
Software Engineering · 2026
Software Engineering

Vector Databases 5/5: Local Qdrant and Cloudflare Architecture

Build a persistent local semantic-search prototype with Python and Qdrant, then design a production architecture using D1, Vectorize and Workers.

Developer's JournalPublished: Nov 26, 20265 min read
Reading progress0%

Pilot goal and setup

A persistent local semantic-search prototype can use the Qdrant Python client's disk-backed local mode without Docker or a paid API. Create a Python virtual environment and install qdrant-client and sentence-transformers. The encoder may download model weights on first use; check storage, license and versions. Local mode is for development and testing, not evidence of production capacity. Use fictional property descriptions initially and protect real records.

python -m venv .venv
.\.venv\Scripts\python.exe -m pip install qdrant-client sentence-transformers

Persistent collection and embeddings

Save the example as demo.py. A multilingual MiniLM sentence encoder produces normalized embeddings, and collection dimensions match the model. QdrantClient(path=...) persists records on disk. Do not recreate an existing collection; upsert stable sample IDs to avoid duplicate records across runs. Use a new collection for a new model, even if vector dimensions match. All hotel descriptions are fictional.

Database access flowConceptual sketch · summary of the article's technical flow
Original technical illustration; conceptual, not a measured result.
from sentence_transformers import SentenceTransformer
from qdrant_client import QdrantClient, models

model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
client = QdrantClient(path='./vector_data')
collection = 'hotels_minilm_v1'
dim = model.get_sentence_embedding_dimension()
if not client.collection_exists(collection):
    client.create_collection(collection_name=collection,
        vectors_config=models.VectorParams(size=dim, distance=models.Distance.COSINE))

items = [
    (1, 'Kastamonu', 'Orman icinde sessiz bungalov, dogada yuruyus ve sakinlik'),
    (2, 'Antalya', 'Aquaparkli aile oteli, cocuk havuzu ve eglence'),
    (3, 'Istanbul', 'Sehir merkezinde toplanti salonlu is oteli'),
    (4, 'Antalya', 'Sakin bahceli butik otel, denize yakin')
]
vectors = model.encode([row[2] for row in items], normalize_embeddings=True)
client.upsert(collection_name=collection, points=[
    models.PointStruct(id=row[0], vector=vec.tolist(),
        payload={'city':row[1], 'description':row[2]})
    for row, vec in zip(items, vectors)
])

Semantic queries and exact filters

Append the query example to demo.py. Encode the question with the same model and retrieve nearest records using query_points. The city filter excludes properties outside Antalya. Only two sample records match, so requesting three cannot produce a third eligible result. Without the filter, other cities become candidates. Scores express model similarity rather than customer satisfaction probabilities. Diagnose unexpected rankings by examining query wording, content and filters.

query = 'cocugumla eglenceli bir tatil yapmak istiyorum'
q = model.encode(query, normalize_embeddings=True).tolist()
result = client.query_points(
    collection_name=collection, query=q, limit=3,
    query_filter=models.Filter(must=[models.FieldCondition(
        key='city', match=models.MatchValue(value='Antalya'))]),
    with_payload=True
)
for point in result.points:
    print(point.id, round(point.score, 4), point.payload)
client.close()
# Run: .\.venv\Scripts\python.exe demo.py

Evaluate the local prototype

Run the program, record results and restart to check that the collection persists without duplicate IDs. Separate initial model download time from query latency. Prepare 30–100 labelled queries, including negation, wrong amenities, synonyms and Turkish characters. Compare a lexical baseline against embedding retrieval, then test alternatives if needed. The listing is a reference example, not a report of an executed model benchmark.

Cloudflare architecture: keep D1

D1 or another SQL database remains the authoritative source for property ID, name, location, activity, price and website. A Worker receives queries, embeds them with a compatible model and queries Vectorize. The vector record ID points back to an authoritative D1 record or chunk; fetch candidates and re-check current status and permissions. R2 can store larger documents and images. Treat the vector index as a rebuildable read layer. A different cloud encoder requires re-embedding.

Updates, backups and cost

Track content hashes, source revisions and model versions to avoid redundant embedding work. Retry failed index writes through a bounded queue and remove obsolete vectors while checking authoritative activity status. Back up local vector_data when the client is closed; preserve original data, indexing scripts and model version. Cloud costs depend on dimensions, counts, query volume, model calls, database reads and storage. Verify current provider quotas and pricing: a free local pilot does not guarantee free production.

Production readiness decisions

Begin with synthetic or approved samples. Define success criteria in advance: relevance in the top five, p95 latency, filter leakage and query cost. Create a controlled test index from only required D1 descriptions without changing production records. Compare in shadow mode before exposing results, then roll out gradually with a lexical fallback. The objective is not acquiring a vector database; it is measurably better information retrieval.

Sources and all five chapters

This is part 5 of a five-part series. Start with the foundations or jump directly to another chapter. The links below lead to the other articles in the same series, followed by primary technical references. Code listings are educational examples; evaluate performance and model relevance in your own environment.

Be the first reader ✎ Write a comment

Reader discussion

Discussion prompt

Bu gelişmeyi kendi alanınızda uygulamadan önce hangi veriyi doğrulamak isterdiniz?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.