Skip to contentমূল লেখায় যান

Topic 30 · AI/ML testingটপিক 30 · AI/ML testing

Vector Database Fundamentals

A vector database stores vectors and finds the nearest ones. Everything else about it is a set of decisions about distance, filtering, and persistence.

10 min read10 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 6 sources6টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Cosine, dot product or distanceকোসাইন, ডট প্রোডাক্ট নাকি দূরত্ব

Change a vector's length and see which metric changes the ranking.একটা ভেক্টরের দৈর্ঘ্য বদলান আর দেখুন কোন মেট্রিকে র‍্যাঙ্ক বদলায়।

3 min3 মিনিট8 steps8টি ধাপ
  • Chunks storedজমা চাঙ্ক3
  • B lengthB-এর দৈর্ঘ্য1×
storeজমাAABBCCarrow = vectorতীর = ভেক্টরqueryকোয়েরিVectorভেক্টরdatabaseডেটাবেস3 chunks stored3টি চাঙ্ক জমাid · vector · metadataid · ভেক্টর · মেটাডেটাAAchunk Aচাঙ্ক Avector (0.9, 0.4)ভেক্টর (0.9, 0.4)source: returnsসোর্স: returnsBBchunk Bচাঙ্ক Bvector (0.5, 0.1)ভেক্টর (0.5, 0.1)source: returnsসোর্স: returnsCCchunk Cচাঙ্ক Cvector (0.3, 0.9)ভেক্টর (0.3, 0.9)source: shippingসোর্স: shipping

You’ll learnআপনি শিখবেন

  • What each metric measuresপ্রতিটা মেট্রিক কী মাপে
  • Why length moves dot and euclid, not cosineদৈর্ঘ্যে কেন ডট ও ইউক্লিড বদলায়, কোসাইন নয়
  • What a metadata filter doesমেটাডেটা ফিল্টার কী করে
  • What to test after a restartরিস্টার্টের পর কী টেস্ট করবেন
  • Why the metric must match the modelমেট্রিক কেন মডেলের সাথে মিলতে হবে

In plain words

A vector database does one thing: given a vector, find the stored vectors nearest to it. Everything else is a set of decisions about distance, filtering, and persistence.

ChromaDB stores embeddings with metadata, searches them, and filters by metadata; you can run it locally, self-host it, or use Chroma Cloud Source 1সোর্স 1. The examples here use its persistent client (a directory on disk), which is the fast way to get a working index. Qdrant is a vector search engine, usually run as a local or cloud service Source 2সোর্স 2. Its docs cover similarity search, filtering, and hybrid queries Source 2সোর্স 2. Filtering works best with payload indexes on the fields you filter on Source 3সোর্স 3. The two behave differently enough that the filter and persistence tests are worth running against both.

The similarity metric decides what "nearest" means, and the choice is not cosmetic:

cosine similarity    the angle between the vectors. Scale-independent.
dot product          the length times the cosine. Favours vectors with large magnitude.
euclidean distance   the straight-line distance. Sensitive to vector length.

Text embeddings are normally compared with cosine similarity, but the two databases do not share a default. Chroma's space defaults to l2 (squared L2), with cosine and ip (inner product) as the other values Source 5সোর্স 5. Qdrant makes you pick a distance (Cosine, Dot, Euclid, or Manhattan) when the collection is created Source 6সোর্স 6. Using euclidean on vectors meant for cosine works, but it ranks differently and can rank worse.

Metadata filtering is the other decision, and it is the one that changes how you design the schema. A filter like "only documents from 2026" can be applied before the search, after it, or during it. Applied before or during, the top-k is taken from the filtered set, and it is usually faster. (An approximate index can still miss neighbours; Qdrant's exact: true forces a full scan.) Applied after, the database searches everything and then throws most away. So the top-k you get back is not the true top-k of the filtered set.

সহজ English

A vector database does one job. You give it a vector, and it finds the stored vectors nearest to it. Everything else is a choice about distance, filtering, and saving data to disk.

ChromaDB stores embeddings with metadata, searches them, and filters by metadata. You can run it locally, self-host it, or use Chroma Cloud Source 1সোর্স 1. The examples here use its persistent client, which saves data in a folder on disk. It is the fast way to get a working index. Qdrant is a vector search engine. You usually run it as a local or cloud service. Its docs cover similarity search, filtering, and hybrid queries Source 2সোর্স 2. Filtering works best when you add payload indexes on the fields you filter on Source 3সোর্স 3. The two behave quite differently. So run the filter and persistence tests against both.

The similarity metric decides what "nearest" means. The choice matters a lot:

cosine similarity    the angle between the vectors. Scale-independent.
dot product          the length times the cosine. Favours vectors with large magnitude.
euclidean distance   the straight-line distance. Sensitive to vector length.

Text embeddings are normally compared with cosine similarity. But the two databases do not share a default. In Chroma, space defaults to l2 (squared L2). The other values are cosine and ip (inner product) Source 5সোর্স 5. Qdrant makes you pick a distance when you create the collection: Cosine, Dot, Euclid, or Manhattan Source 6সোর্স 6. Euclidean on vectors meant for cosine still works. But it ranks differently, and the ranking can be worse.

Metadata filtering is the other choice. It changes how you design the schema. A filter such as "only documents from 2026" can run before the search, after it, or during it. Before or during, the top-k is taken from the filtered set, and it is usually faster. (An approximate index can still miss neighbours; Qdrant's exact: true forces a full scan.) After the search, the database searches everything and throws most results away. Then the top-k you get is not the true top-k of the filtered set.

বাংলা ব্যাখ্যা

vector database একটাই কাজ করে: একটা vector দিলে সবচেয়ে কাছের সংরক্ষিত vectorগুলো খুঁজে বের করে। বাকি সব হলো distance, filtering আর persistence নিয়ে কিছু সিদ্ধান্ত।

ChromaDB metadata-সহ embedding রাখে, search করে আর metadata দিয়ে filter করে; এটা local-এ চালানো, নিজে host করা বা Chroma Cloud-এ ব্যবহার করা যায় Source 1সোর্স 1। এখানকার উদাহরণে এর persistent client (ডিস্কে একটা directory) ব্যবহার হয়েছে, কাজ করা index দ্রুত পেতে এটাই সহজ। Qdrant একটা vector search engine, সাধারণত local বা cloud service হিসেবে চালানো হয়; এর docs similarity search, filtering আর hybrid query কভার করে Source 2সোর্স 2; যে field-এ filter করেন সেগুলোতে payload index থাকলে filtering ভালো কাজ করে Source 3সোর্স 3।

Similarity metric ঠিক করে "কাছের" মানে কী, আর এই সিদ্ধান্ত সাজসজ্জার নয়:

cosine similarity    the angle between the vectors. Scale-independent.
dot product          the length times the cosine. Favours vectors with large magnitude.
euclidean distance   the straight-line distance. Sensitive to vector length.

Text embedding সাধারণত cosine similarity দিয়ে তুলনা করা হয়, কিন্তু দুটো database-এর default এক নয়। Chroma-র space default l2 (squared L2), অন্য মান cosine আর ip (inner product) Source 5সোর্স 5, আর Qdrant collection বানানোর সময় আপনাকে distance (Cosine, Dot, Euclid, বা Manhattan) বেছে নিতে হয় Source 6সোর্স 6। cosine-এর জন্য তৈরি vector নিয়ে euclidean ব্যবহার করলে কাজ করে, কিন্তু rank আলাদা হয়, আর rank খারাপও হতে পারে।

Metadata filtering হলো আরেকটি সিদ্ধান্ত, আর এটাই schema কীভাবে ডিজাইন করবেন তা বদলে দেয়। "শুধু ২০২৬-এর document" ফিল্টারটা search-এর আগে, পরে, বা চলাকালে প্রয়োগ করা যায়। আগে বা চলাকালে প্রয়োগ করলে top-k filtered set থেকেই আসে আর সাধারণত দ্রুত হয়। (approximate index তবুও কিছু প্রতিবেশী মিস করতে পারে; Qdrant-এর exact: true পুরো scan করায়।) পরে প্রয়োগ করলে database সব খুঁজে বের করে তারপর বেশিরভাগ ফেলে দেয়, আর যে top-k আপনি পান সেটা filtered set-এর আসল top-k নয়।

How it works

The insert-and-query cycle is the same in both databases, and the test is the same too: you know what you put in and what you expect back.

Ingestion. Every chunk becomes an id, a vector, and a metadata document. The metadata is what makes filtering possible later, so it is worth deciding early which fields you will filter on: the document id, the source file, the page number, the date, the language, the product, the version.

Query. A question is embedded with the same model that embedded the documents, and the database compares it against the stored vectors. Chroma's query interface takes the query text or an embedding plus the number of results and a filter Source 4সোর্স 4. Qdrant's search API does the same with its filter language Source 3সোর্স 3.

The metric has to match the model. For many text embedding models the vector length carries no ranking information, so cosine is the usual choice; check the model card for the metric it was trained for. It is a setting you choose, not a default you can rely on. Setting the metric to euclidean on a model meant for cosine can give you results that are consistent and wrong: the same query returns the same neighbours every time, and the neighbours are not the semantically closest ones.

The two databases differ in what they optimise. Chroma's persistent client is simple to run locally: one directory, no separate server to run. Qdrant is a service: it has payload indexes and a combined filterable index that applies filters during the search Source 3সোর্স 3. The choice for a tester is mostly about whether you need to test the filter behaviour separately or not.

The persistence question. Chroma's persistent client writes to a directory; Qdrant persists to its own storage. Either way, the testable property is the same: after a restart, the collection holds the same vectors and returns the same neighbours for the same query. A vector database that loses its index on restart is a silent data-loss bug, and it shows up as "the chatbot suddenly stopped knowing things".

সহজ English

The insert-and-query steps are the same in both databases. The test is the same too. You know what you put in, and you know what you expect back.

Ingestion. Every chunk becomes an id, a vector, and a metadata document. Metadata is what makes filtering possible later. So decide early which fields you will filter on. Examples are the document id, source file, page number, date, language, product, and version.

Query. You embed the question with the same model that embedded the documents. The database then compares it with the stored vectors. Chroma's query interface takes the query text or an embedding, the number of results, and a filter Source 4সোর্স 4. Qdrant's search API does the same with its own filter language Source 3সোর্স 3.

The metric has to match the model. For many text embedding models, vector length carries no ranking information. So cosine is the usual choice. Check the model card for the metric the model was trained for. You must set it yourself. Do not rely on a default. Euclidean on a model meant for cosine can give results that are consistent and wrong. The same query returns the same neighbours every time. But those neighbours are not the semantically closest ones.

The two databases optimise different things. Chroma's persistent client is simple to run locally. It has one directory and no separate server to run. Qdrant is a service. It has payload indexes and a combined filterable index that applies filters during the search Source 3সোর্স 3. For a tester, the choice is mostly about whether you need to test filter behaviour separately.

The persistence question. Chroma's persistent client writes to a directory. Qdrant saves to its own storage. Either way, the testable property is the same: after a restart, the collection holds the same vectors and returns the same neighbours for the same query. If the index is lost on restart, that is a silent data-loss bug. It shows up as "the chatbot suddenly stopped knowing things".

বাংলা ব্যাখ্যা

insert আর query-এর চক্র দুটো database-এ এক, আর টেস্টও এক: আপনি জানেন কী দিয়েছেন আর কী ফেরত পাবেন বলে ধারণা করেছেন।

Ingestion। প্রতিটা chunk হয় একটা id, একটা vector, আর একটা metadata document। metadata-ই পরে filtering সম্ভব করে, তাই আগে ঠিক করে নিন কোন field-এ filter করবেন: document id, source file, page number, date, language, product, version।

Query। প্রশ্নটা একই model দিয়ে embed হয় যেটা document embed করেছিল, আর database সেটা সংরক্ষিত vector-এর সাথে তুলনা করে। Chroma-র query interface query text বা embedding নেয়, সাথে result-এর সংখ্যা আর filter Source 4সোর্স 4। Qdrant-এর search API একই কাজ করে তার filter ভাষা দিয়ে Source 3সোর্স 3।

metric-কে model-এর সাথে মেলাতে হবে। অনেক text embedding model-এর vector-এর দৈর্ঘ্য ranking-এর জন্য কোনো তথ্য বহন করে না, তাই সাধারণত cosine বেছে নেওয়া হয়; model card-এ দেখে নিন model কোন metric-এ train হয়েছে। এটা আপনার বেছে নেওয়া setting, ভরসা করার মতো default নয়। cosine-এর জন্য তৈরি model-এর ওপর euclidean বসালে ফলাফল সামঞ্জস্যপূর্ণ ও ভুল হয়: একই query প্রতিবার একই প্রতিবেশী ফেরত দেয়, আর সেই প্রতিবেশীরা অর্থের দিক থেকে সবচেয়ে কাছের নয়।

দুটো database কী অপটিমাইজ করে তা আলাদা। Chroma-র persistent client local-এ চালানো সহজ: একটা directory, আলাদা কোনো server চালাতে হয় না। Qdrant একটা service: এর payload index আর একটা combined filterable index আছে যা search-এর সময়ই filter প্রয়োগ করে Source 3সোর্স 3। টেস্টারের জন্য সিদ্ধান্তটা মূলত এটা যে filter-এর আচরণ আলাদা করে টেস্ট করতে হবে কি না।

Persistence-এর প্রশ্ন। Chroma-র persistent client একটা directory-তে লেখে; Qdrant নিজস্ব storage-এ রাখে। যেকোনো উপায়ে, টেস্ট করার যোগ্য গুণ একই: restart-এর পর collection-এ একই vector আছে আর একই query-তে একই প্রতিবেশী ফেরত দেয়। restart-এ index হারানো vector database একটা নীরব data-loss বাগ, আর তার চিহ্ন হলো "chatbot হঠাৎ কিছু জানতে পারছে না"।

In practice

Test the database as a component, with a small fixed corpus where you know the right answer for every query:

# tests/ai/test_vector_db.py
import subprocess
import sys

import chromadb
import pytest
from qdrant_client import QdrantClient, models

from app.knowledge import embed, index_documents

CORPUS = {
    "returns#chunk-1": "Unopened items can be returned within 30 days.",
    "returns#chunk-2": "Opened items cannot be returned.",
    "shipping#chunk-1": "We pay the return shipping for defects.",
}


@pytest.fixture
def collection(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    return index_documents(client.get_or_create_collection("docs"), CORPUS)

Then the tests that matter, in order of how often they catch something:

def test_the_closest_chunk_is_the_right_one(collection):
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1"
def test_a_filter_excludes_the_other_documents(collection):
    hits = collection.query(
        query_texts=["return window"],
        n_results=3,
        where={"source": "returns"},
    )
    assert all(h.startswith("returns#") for h in hits["ids"][0])
def test_the_query_is_deterministic(collection):
    first = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    second = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    assert first == second, "the same query returned different neighbours"
def test_the_collection_survives_a_restart(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = index_documents(client.get_or_create_collection("docs"), CORPUS)
    del collection, client

    # reopen in a fresh process, so the test cannot pass on in-process state
    script = (
        "import chromadb, sys;"
        "c = chromadb.PersistentClient(path=sys.argv[1]).get_collection('docs');"
        "r = c.query(query_texts=['return window'], n_results=1);"
        "print(c.count(), r['ids'][0][0])"
    )
    out = subprocess.run(
        [sys.executable, "-c", script, str(tmp_path)],
        capture_output=True, text=True, check=True,
    ).stdout.split()
    assert int(out[0]) == len(CORPUS)
    assert out[1] == "returns#chunk-1"

The last one is the test that catches data loss, and it is the one teams skip because it needs a fresh process, which is why the reopen runs in a subprocess.

Then the metric comparison, which is the test that shows whether the space you chose is right for your model:

@pytest.mark.parametrize("space", ["cosine", "l2", "ip"])
def test_each_space_ranks_the_right_chunk_first(tmp_path, space):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = client.create_collection("docs", configuration={"hnsw": {"space": space}})
    index_documents(collection, CORPUS)
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1", f"{space} ranked it wrong"

And the Qdrant filter test, which is where the two databases differ most:

@pytest.fixture
def qdrant_client():
    # assumes an in-memory client; create the "docs" collection and upsert the
    # CORPUS vectors (with a "source" payload) here before the test runs
    return QdrantClient(":memory:")


def test_qdrant_filters_inside_the_search(qdrant_client):
    hits = qdrant_client.query_points(
        collection_name="docs",
        query=embed("return window"),
        limit=3,
        query_filter=models.Filter(must=[models.FieldCondition(key="source", match=models.MatchValue(value="returns"))]),
    ).points
    assert all(h.payload["source"] == "returns" for h in hits)

That test is worth writing because Qdrant applies the filter during the search, through a combined filterable index Source 3সোর্স 3, and a filter applied after the search would return a different top-k.

সহজ English

Test the database as a single component. Use a small fixed corpus where you know the right answer for every query:

# tests/ai/test_vector_db.py
import subprocess
import sys

import chromadb
import pytest
from qdrant_client import QdrantClient, models

from app.knowledge import embed, index_documents

CORPUS = {
    "returns#chunk-1": "Unopened items can be returned within 30 days.",
    "returns#chunk-2": "Opened items cannot be returned.",
    "shipping#chunk-1": "We pay the return shipping for defects.",
}


@pytest.fixture
def collection(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    return index_documents(client.get_or_create_collection("docs"), CORPUS)

Next come the tests that matter. They are listed by how often they catch a problem. The first one checks that the closest chunk is the right one:

def test_the_closest_chunk_is_the_right_one(collection):
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1"

The second checks that a filter leaves out the other documents:

def test_a_filter_excludes_the_other_documents(collection):
    hits = collection.query(
        query_texts=["return window"],
        n_results=3,
        where={"source": "returns"},
    )
    assert all(h.startswith("returns#") for h in hits["ids"][0])

The third checks that the same query gives the same answer twice:

def test_the_query_is_deterministic(collection):
    first = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    second = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    assert first == second, "the same query returned different neighbours"

The fourth checks that the collection survives a restart:

def test_the_collection_survives_a_restart(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = index_documents(client.get_or_create_collection("docs"), CORPUS)
    del collection, client

    # reopen in a fresh process, so the test cannot pass on in-process state
    script = (
        "import chromadb, sys;"
        "c = chromadb.PersistentClient(path=sys.argv[1]).get_collection('docs');"
        "r = c.query(query_texts=['return window'], n_results=1);"
        "print(c.count(), r['ids'][0][0])"
    )
    out = subprocess.run(
        [sys.executable, "-c", script, str(tmp_path)],
        capture_output=True, text=True, check=True,
    ).stdout.split()
    assert int(out[0]) == len(CORPUS)
    assert out[1] == "returns#chunk-1"

This last test catches data loss. Teams often skip it because it needs a fresh process, which is why the reopen runs in a subprocess.

Then comes the metric comparison. It shows whether the space you chose is right for your model:

@pytest.mark.parametrize("space", ["cosine", "l2", "ip"])
def test_each_space_ranks_the_right_chunk_first(tmp_path, space):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = client.create_collection("docs", configuration={"hnsw": {"space": space}})
    index_documents(collection, CORPUS)
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1", f"{space} ranked it wrong"

Last is the Qdrant filter test. This is where the two databases differ most:

@pytest.fixture
def qdrant_client():
    # assumes an in-memory client; create the "docs" collection and upsert the
    # CORPUS vectors (with a "source" payload) here before the test runs
    return QdrantClient(":memory:")


def test_qdrant_filters_inside_the_search(qdrant_client):
    hits = qdrant_client.query_points(
        collection_name="docs",
        query=embed("return window"),
        limit=3,
        query_filter=models.Filter(must=[models.FieldCondition(key="source", match=models.MatchValue(value="returns"))]),
    ).points
    assert all(h.payload["source"] == "returns" for h in hits)

Write this test because Qdrant applies the filter during the search, through a combined filterable index Source 3সোর্স 3. A filter applied after the search would return a different top-k.

বাংলা ব্যাখ্যা

database-কে একটা component হিসেবে টেস্ট করুন, ছোট একটা নির্দিষ্ট corpus দিয়ে যেখানে প্রতিটা query-এর সঠিক উত্তর আপনি জানেন:

# tests/ai/test_vector_db.py
import subprocess
import sys

import chromadb
import pytest
from qdrant_client import QdrantClient, models

from app.knowledge import embed, index_documents

CORPUS = {
    "returns#chunk-1": "Unopened items can be returned within 30 days.",
    "returns#chunk-2": "Opened items cannot be returned.",
    "shipping#chunk-1": "We pay the return shipping for defects.",
}


@pytest.fixture
def collection(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    return index_documents(client.get_or_create_collection("docs"), CORPUS)

তারপর গুরুত্বপূর্ণ টেস্টগুলো, কোনটা কত ঘন ঘন কিছু ধরে সেই ক্রমে:

def test_the_closest_chunk_is_the_right_one(collection):
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1"
def test_a_filter_excludes_the_other_documents(collection):
    hits = collection.query(
        query_texts=["return window"],
        n_results=3,
        where={"source": "returns"},
    )
    assert all(h.startswith("returns#") for h in hits["ids"][0])
def test_the_query_is_deterministic(collection):
    first = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    second = collection.query(query_texts=["return window"], n_results=5)["ids"][0]
    assert first == second, "the same query returned different neighbours"
def test_the_collection_survives_a_restart(tmp_path):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = index_documents(client.get_or_create_collection("docs"), CORPUS)
    del collection, client

    # reopen in a fresh process, so the test cannot pass on in-process state
    script = (
        "import chromadb, sys;"
        "c = chromadb.PersistentClient(path=sys.argv[1]).get_collection('docs');"
        "r = c.query(query_texts=['return window'], n_results=1);"
        "print(c.count(), r['ids'][0][0])"
    )
    out = subprocess.run(
        [sys.executable, "-c", script, str(tmp_path)],
        capture_output=True, text=True, check=True,
    ).stdout.split()
    assert int(out[0]) == len(CORPUS)
    assert out[1] == "returns#chunk-1"

শেষ টেস্টটাই data loss ধরে, আর দলগুলো বাদ দেয় কারণ এর জন্য নতুন প্রসেস লাগে, তাই reopen-টা subprocess-এ চালানো হয়েছে।

তারপর metric তুলনা, যেটা দেখায় আপনার বেছে নেওয়া space আপনার model-এর জন্য ঠিক কি না:

@pytest.mark.parametrize("space", ["cosine", "l2", "ip"])
def test_each_space_ranks_the_right_chunk_first(tmp_path, space):
    client = chromadb.PersistentClient(path=str(tmp_path))
    collection = client.create_collection("docs", configuration={"hnsw": {"space": space}})
    index_documents(collection, CORPUS)
    hits = collection.query(query_texts=["how long is the return window?"], n_results=1)
    assert hits["ids"][0][0] == "returns#chunk-1", f"{space} ranked it wrong"

আর Qdrant filter টেস্ট, যেখানে দুটো database-এর সবচেয়ে বেশি পার্থক্য:

@pytest.fixture
def qdrant_client():
    # assumes an in-memory client; create the "docs" collection and upsert the
    # CORPUS vectors (with a "source" payload) here before the test runs
    return QdrantClient(":memory:")


def test_qdrant_filters_inside_the_search(qdrant_client):
    hits = qdrant_client.query_points(
        collection_name="docs",
        query=embed("return window"),
        limit=3,
        query_filter=models.Filter(must=[models.FieldCondition(key="source", match=models.MatchValue(value="returns"))]),
    ).points
    assert all(h.payload["source"] == "returns" for h in hits)

টেস্টটা লেখার দরকার কারণ Qdrant filter-টা search-এর সময়ই প্রয়োগ করে, একটা combined filterable index দিয়ে Source 3সোর্স 3, আর search-এর পরে filter চালালে একটা ভিন্ন top-k ফেরত আসত।

Common mistakes

Mistake 1: using euclidean because the docs mention it. The metric has to match the model the vectors came from. Chroma's default space is l2, and text embeddings are normally compared with cosine, so set it deliberately Source 5সোর্স 5.

Mistake 2: no filter test. Filtering is where the two databases behave differently, and where a wrong top-k hides Source 3সোর্স 3.

Mistake 3: no restart test. A vector database that loses its index on restart loses data quietly.

Mistake 4: filtering after the search. The top-k you get is then the top-k of the unfiltered set, not of the filtered one.

Mistake 5: no metadata schema. Deciding which fields you filter on after the first production incident means a re-index of everything.

Mistake 6: testing against a live corpus. The test needs a fixed corpus where the right answer is known, so a failure is a failure and not a different day.

সহজ English

Mistake 1: picking euclidean because the docs mention it. The metric must match the model that made the vectors. Chroma's default space is l2. Text embeddings are normally compared with cosine. So set the space on purpose Source 5সোর্স 5.

Mistake 2: no filter test. The two databases behave differently when they filter. A wrong top-k can hide there Source 3সোর্স 3.

Mistake 3: no restart test. If a vector database loses its index on restart, it loses data quietly.

Mistake 4: filtering after the search. Then the top-k you get comes from the unfiltered set. It does not come from the filtered one.

Mistake 5: no metadata schema. Suppose you decide on filter fields only after the first production incident. Then you must re-index everything.

Mistake 6: testing against a live corpus. Use a fixed corpus where the right answer is known. Then a failure is a real failure, and not just a different day.

বাংলা ব্যাখ্যা

Mistake ১: ডকুমেন্টে উল্লেখ আছে বলে euclidean ব্যবহার করা। metric-কে model-এর সাথে মেলাতে হবে যার থেকে vector এসেছে। Chroma-র default space l2, আর text embedding সাধারণত cosine দিয়ে তুলনা করা হয়, তাই এটা ইচ্ছাকৃতভাবে সেট করুন Source 5সোর্স 5।

Mistake ২: filter টেস্ট নেই। filtering-এই দুটো database আলাদা আচরণ করে, আর ভুল top-k লুকিয়ে থাকে Source 3সোর্স 3।

Mistake ৩: restart টেস্ট নেই। restart-এ index হারানো vector database নীরবে data হারায়।

Mistake ৪: search-এর পরে filtering। তখন যে top-k পাবেন সেটা filtered set-এর নয়, unfiltered set-এর top-k।

Mistake ৫: metadata schema নেই। production-এর প্রথম incident-এর পরে কোন field-এ filter করবেন ঠিক করলে সবকিছু আবার index করতে হয়।

Mistake ৬: live corpus-এর বিপরীতে টেস্ট করা। টেস্টে নির্দিষ্ট corpus দরকার যেখানে সঠিক উত্তর জানা, যাতে ব্যর্থতা মানে ব্যর্থতা হয় আর আলাদা দিনের ব্যাপার না।

What a tester can check

Tutorial advice

This advice is the tutorial's own. It does not come from the sources.

  • Give every chunk a stable id built from the document id and the chunk index. The id is what every assertion refers to.
  • Store the metadata you filter on in a fixed list, and test that every chunk has every field. A missing metadata field is an invisible filter bug.
  • Run the same suite against Chroma and Qdrant if you use both. The contract you wrote should hold for both.
  • Keep the restart test in the fast suite. It needs a temp directory, not a database.
  • Test an empty collection. A query against nothing should return an empty result, not an error and not the whole collection.
  • Test a query in a language the corpus does not contain. It is the cheapest way to see the embedding model's language coverage.

সহজ English

Tutorial advice

This advice is the tutorial's own. It does not come from the sources.

  • Give every chunk a stable id built from the document id and the chunk index. The id is what every assertion refers to.
  • Store the metadata you filter on in a fixed list, and test that every chunk has every field. A missing metadata field is an invisible filter bug.
  • Run the same suite against Chroma and Qdrant if you use both. The contract you wrote should hold for both.
  • Keep the restart test in the fast suite. It needs a temp directory, not a database.
  • Test an empty collection. A query against nothing should return an empty result, not an error and not the whole collection.
  • Test a query in a language the corpus does not contain. It is the cheapest way to see the embedding model's language coverage.

বাংলা ব্যাখ্যা

Tutorial advice

এই পরামর্শ টিউটোরিয়ালের নিজস্ব। এটি সোর্স থেকে আসেনি।

  • প্রতিটা chunk-কে document id আর chunk index দিয়ে স্থায়ী id দিন। প্রতিটা assertion এই id-কেই ধরে।
  • যে metadata-তে filter করবেন সেগুলো একটা নির্দিষ্ট তালিকায় রাখুন, আর টেস্ট করুন প্রতিটা chunk-এ প্রতিটা field আছে কি না। metadata field না থাকলে filter বাগ দেখা যায় না।
  • দুটোই ব্যবহার করলে একই suite Chroma আর Qdrant-এর ওপর চালান। আপনার লেখা contract দুটোর জন্যই কাজ করা উচিত।
  • restart টেস্টটা দ্রুত suite-এ রাখুন। এর জন্য database নয়, একটা temp directory লাগে।
  • খালি collection টেস্ট করুন। কিছুর ওপর query করলে খালি ফলাফল আসা উচিত, error নয় আর পুরো collection নয়।
  • corpus-এ যে ভাষা নেই সেই ভাষায় query টেস্ট করুন। embedding model-এর ভাষা coverage দেখার সবচেয়ে সস্তা উপায় এটাই।

Key words

WordWhat it means
Vector databaseA store that finds the stored vectors nearest to a query vector
Cosine similarityThe angle between two vectors; the usual metric for text embeddings
Euclidean distanceThe straight-line distance between vectors; sensitive to their length
Dot productThe length times the cosine; favours vectors with a large magnitude
Metadata filterA condition on the stored records, applied during or after the search
Payload indexQdrant's index that makes filtering part of the search
Persistent clientChroma's mode that writes the collection to a directory on disk
NeighbourOne of the stored records the search returns
DeterminismThe same query returning the same neighbours every time

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    Introduction

    Chroma (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  2. [2]
    What is Qdrant?

    Qdrant (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  3. [3]
    Search

    Qdrant (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  4. [4]
    Query and Get

    Chroma (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  5. [5]
    Configure collections

    Chroma (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01

  6. [6]
    Collections

    Qdrant (docs) · accessed 2026-11-01দেখা হয়েছে: 2026-11-01