Store documents with metadata in Qdrant and filter by department

Qdrant stores each vector together with a JSON payload and can filter searches on that payload. This tutorial uses the Python client to save chunks with department and access group and to restrict a search to one department.

Niklas Schult4 min read

Illustration: A filing cabinet with tagged drawers; a funnel over one open drawer collects only the beads from that drawer.

What you will build and what you need first

At the end you will have a small Qdrant collection in which every point carries a department, an access group and the chunk text. You will also run a search that returns only points of one department. Enterprise search that respects permissions rests on this building block.

You need Docker, Python and the Python client from the Qdrant README. The vectors in this example have four dimensions and are written by hand. In a real system an embedding model produces them, and the README does not cover that step.

The README describes Qdrant as a vector similarity search engine and vector database. It is tailored for extended filtering support, which is the reason it suits permission-aware search. The tutorial keeps to a single collection and two points so that you can see each effect of the filter directly.

Start the server and connect

The README starts a local server with one container command. It maps port 6333 and runs the image qdrant/qdrant.

Shell
docker run -p 6333:6333 qdrant/qdrant

The README warns that this deployment has no authentication and listens on all network interfaces. Use it only for testing, and read the security guide before anything goes to production. The next block connects the Python client to the running server.

Python
from qdrant_client import QdrantClient

client = QdrantClient(url="http://localhost:6333")

Store chunks with a payload

Qdrant calls a vector with an additional payload a point. The payload accepts any JSON, so department, access group and the chunk text can sit next to the vector. The following block creates a collection named docs with cosine distance and four dimensions, then writes two points for different departments.

Python
from qdrant_client.models import Distance, VectorParams, PointStruct

client.create_collection(
    collection_name="docs",
    vectors_config=VectorParams(size=4, distance=Distance.COSINE),
)
client.upsert(
    collection_name="docs",
    points=[
        PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4],
            payload={"department": "hr", "access_group": "hr-team",
                     "text": "Urlaubsregelung"}),
        PointStruct(id=2, vector=[0.2, 0.1, 0.4, 0.3],
            payload={"department": "finance", "access_group": "finance-team",
                     "text": "Reisekosten"}),
    ],
)

Each point has an id and a vector, and the payload holds everything you later want to filter on. Because the payload is plain JSON, you can add further fields such as a document name or a page number without changing the collection definition. Decide early which fields you need for permissions, since every chunk must carry them.

Check the result and avoid common mistakes

The script should print only point 1 with the text Urlaubsregelung. If you change the value to finance, point 2 should appear instead. Without the filter both points are candidates, so a changed result confirms that the filter is applied.

The README names a few points that matter here. The test container has no authentication, so anyone who reaches port 6333 can read every payload. The README also lists payload indexes, which Qdrant uses for query planning, but it does not show how to create them, so check the documentation before loading large collections. The filter also works only on what you stored, which means every chunk needs its department and group written at upload time.

Where this fits in a company

A payload filter is one layer of a permission model. The application must still look up the groups of the signed-in user and pass them into the filter on every query. Someone in IT has to own that mapping, keep the payload fields in step with changes in the source systems and secure the server. Companies commonly ask their data protection officer and the works council (Betriebsrat) to review such a setup when it indexes personnel or finance documents.

souveraen.ai connects sources such as SharePoint and file servers read-only and with the existing permissions. It runs either hosted in Germany or on-premise. If you would rather not build this yourself, see knowledge management software, the security overview and the on-premise option. Background on running models in your own network is on the local AI page.

Sources

More articles

All articles

OpenAI Private Inference: Is It Fit for Confidential Data?

OpenAI is testing an offer called Private Inference with first business customers, under which the provider is not meant to see the data it processes. Law firms, public bodies and companies with sensitive files need to know whether this makes ChatGPT services usable for confidential content.

Data protection4 min

Self-host Langfuse for LLM monitoring in your company

Langfuse records prompts, answers and costs of AI applications, and the README describes how to run it on your own infrastructure. This tutorial takes you from an empty machine to a first logged model call.

Tutorial4 min

AI applicant profiles: what employers may use from the web

AI tools can turn social media posts and press articles into an applicant profile within seconds. Employers in Germany need to know which public data the GDPR and the BDSG allow them to use in hiring.

Data protection4 min

Test it with your own documents.

Free for 3 days, then from €24.90 per user per month. Cancellable monthly.

Free for 3 days, then from €24.90 per user per month.Free for 3 days
Try free for 3 days