Store and Filter AI Vectors Locally with Qdrant and JavaScript in 5 Steps

A tiny AI search script can keep vectors in memory. The next useful task is different: store those vectors between runs and restrict a search to matching metadata. Qdrant provides a vector database for that job.

This tutorial uses deliberately synthetic four-number vectors, not model-generated embeddings. That keeps the database mechanics visible. It does not demonstrate semantic quality or benchmark performance. The API calls follow Qdrant’s official documentation; the combined example is an original teaching adaptation, not a personally tested deployment.

For generating real embeddings first, see the existing Ollama and JavaScript semantic-search tutorial. That example has no database; this one focuses on persistence and filtering.

1. Start a local-only database with persistent storage

You need Docker running and a currently supported Node.js release with npm. On macOS, Docker Desktop is one option; on Linux, Docker Engine is another. Check Docker’s licensing terms for your situation rather than assuming every distribution is free for every use.

docker volume create qdrant_tutorial_data
docker pull qdrant/qdrant
docker run -d --name qdrant-tutorial \
  -p 127.0.0.1:6333:6333 \
  -v qdrant_tutorial_data:/qdrant/storage \
  qdrant/qdrant

The named volume holds database files outside the container’s writable layer. Do not treat it as a backup. The REST interface and dashboard are available from the host at http://127.0.0.1:6333 and http://127.0.0.1:6333/dashboard.

This adapts Qdrant’s Docker quickstart with a host-loopback port binding. Its default self-hosted configuration has no authentication. A bare -p 6333:6333 can expose it beyond your laptop. Docker also warns that releases older than 28.0.0 have a localhost-publishing caveat for nearby network hosts. Use an updated engine and normal host security controls. Containers sharing the database’s Docker network are a separate access boundary.

2. Create a small JavaScript workspace

mkdir qdrant-filter-demo
cd qdrant-filter-demo
npm init -y
npm install @qdrant/js-client-rest

The package and installation command come from the official JavaScript SDK. Keep the generated lockfile. The untagged Docker image and unpinned initial package installation follow current upstream defaults; record and pin compatible versions before depending on this in an application.

3. Store vectors with useful metadata

Save this as search.mjs. Use a new collection name if this tutorial collection already exists. Do not delete a real collection just to clear an example error.

import { QdrantClient } from '@qdrant/js-client-rest';

const client = new QdrantClient({ url: 'http://127.0.0.1:6333' });
const collection = 'tutorial_filtered_vectors';

await client.createCollection(collection, {
  vectors: { size: 4, distance: 'Dot' },
});

await client.upsert(collection, {
  wait: true,
  points: [
    { id: 1, vector: [1, 0, 0, 0],
      payload: { project: 'demo', title: 'Public sample A' } },
    { id: 2, vector: [0.8, 0.2, 0, 0],
      payload: { project: 'other', title: 'Public sample B' } },
    { id: 3, vector: [0, 1, 0, 0],
      payload: { project: 'demo', title: 'Public sample C' } },
  ],
});

A collection defines vector size and distance metric. A point carries an ID, a vector, and a payload: structured metadata such as a project identifier or document title. wait: true asks the upsert call to wait for the operation to complete.

These arbitrary vectors use dot-product scoring for illustration. Their dimensions and metric are not a recommendation for a particular embedding model. Real queries and stored documents must use the same embedding model and compatible preprocessing.

4. Query only the matching project

Append this to the file:

const result = await client.query(collection, {
  query: [1, 0, 0, 0],
  filter: {
    must: [{ key: 'project', match: { value: 'demo' } }],
  },
  with_payload: true,
  limit: 3,
});

console.log(result.points);

Run the complete example once:

node search.mjs

The intended check is that returned payloads belong to demo, not other. Inspect your actual response; no measured latency or model-quality result is claimed. A limit is a maximum, not a promise of that many matches.

A payload filter is not authorization by itself. If a caller can change or omit the filter, it cannot protect another customer’s documents. Enforce access rules in your application and use appropriate database credentials.

5. Verify persistence without recreating the collection

docker restart qdrant-tutorial

After the service is ready, open the dashboard and check that the collection remains. Do not rerun the full script unchanged: it tries to create the collection again. For subsequent queries, use a separate file containing the client setup, collection name, and query block only.

Symptom First check
Connection refused Check container state and logs; allow startup to complete.
Collection already exists Reuse it with query-only code, or choose a fresh tutorial name.
Vector-size error Match every vector to the collection’s declared size.
Empty filtered result Check payload field names, values, and data types.

Local operation still costs disk space, memory, and electricity. Stored vectors and payloads deserve the same care as source documents. Before any remote deployment, follow Qdrant’s security guidance for authentication, private networking, TLS, and backups. This local example is not a production-hardening checklist.

Documentation checked November 23, 2026. These are living documentation pages; their original publication dates were not established. No personal testing, hardware-fit, star-count, or performance claim is made.


Discover more from Juzhax Technology

Subscribe to get the latest posts sent to your email.

Leave a Reply