Dify vector database selection for knowledge bases

Weaviate is the default vector store for Dify knowledge bases, and the alternatives change how you run, scale and back up retrieval. This page covers how to choose, configure, verify and hand over the choice.

On this page

Why the Dify vector database choice matters for knowledge bases

If you are deploying Dify for retrieval-augmented generation, you have to decide which vector store will hold the embeddings behind your knowledge bases. Weaviate is the default, and the environment variable reference lists Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch as supported options. The choice looks like a configuration detail, but it shapes how your knowledge bases are stored, backed up, upgraded and operated for as long as the deployment runs. Confirm which options your Dify release supports in its environment variable reference before you commit to one.

The choice is hard to reverse because the vector store is set at deployment, and switching later means moving data between stores rather than changing a setting. Exporting a Dify app as YAML DSL keeps the app configuration, workflow nodes, prompts and knowledge base connections, but it does not carry knowledge base content or the embeddings themselves. Your source documents and the indexed vectors therefore have to be recovered from your own backups or re-ingested, so the store you pick determines what a restore or migration involves.

The store also changes who on your team can run it. A team that already operates PostgreSQL may find pgvector easier to back up, monitor and patch alongside the metadata database, while a team that already runs OpenSearch or Elasticsearch may prefer those operational skills. Each option has its own upgrade path, resource profile and backup method, and these should be checked against the Dify version you plan to run. Before deciding, ask who will own the store after go-live, which backup method your organization already audits, and which upgrade guide applies to your target release.

Which Dify components touch the vector store

A knowledge base in Dify spans several services, and only some of them hold vectors. Before choosing a store, map which component writes embeddings, which one queries them, and where the metadata and source files live, because each swap changes a different part of the path.

API and worker services

The api service handles knowledge base queries during chat and workflow runs, while the worker service runs document indexing in the background: it splits uploaded files into chunks, calls the embedding model, and writes the resulting vectors to the configured store. Both services need the vector store connection settings, so a swap means updating the environment variables for both and confirming that indexing and retrieval succeed on a test knowledge base. Ask your team to confirm which services read the vector store configuration in the release you deploy.

Services read the store
2
Environment variable reference

Vector store container or service

The default store is Weaviate, which the Compose stack starts as a container. Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch are alternatives selected through configuration. Each store brings its own storage, backup, memory and upgrade behavior, so the choice moves operational work to a different team. Confirm the exact option names and supported versions against the environment reference for your Dify release before planning the build.

Metadata PostgreSQL database

PostgreSQL holds the knowledge base records, document metadata, segment text and app configuration, even though the vectors themselves may sit elsewhere. A vector store swap does not move these records, so the knowledge base structure survives a change of store, but the vectors must be regenerated or migrated separately. Plan backups of this database as the record of what each knowledge base contains.

Object storage for uploaded files

Original uploaded documents are kept in file storage, which can be local storage, S3-compatible storage, Azure Blob or Google Cloud Storage, depending on configuration. Re-indexing into a new vector store reads these files again, so they must remain intact and reachable during any migration. The YAML export of apps does not include knowledge base content, which makes this storage and the database your only complete source for rebuilding an index.

Embedding model provider

Embeddings are produced by the model provider configured in Dify, not by the vector store. The store only holds the numeric vectors and their dimensions, so the embedding model and its vector size must stay consistent across any migration. Changing the embedding model requires re-indexing every knowledge base, regardless of which store you run. Confirm the embedding model and dimension in each knowledge base before you swap stores.

SSRF proxy and network path

Outbound requests from Dify pass through the SSRF proxy, which blocks internal and private IP ranges by design. An external vector store, such as a separate Qdrant, Milvus or OpenSearch cluster on a private network, must be reachable from api and worker without going through that restriction, so the path needs an explicit allowance in your network design. Test connectivity from both services after every change, and confirm how your deployment routes these connections.

SSRF proxy settings

Weaviate, Qdrant, Milvus, pgvector, OpenSearch or Elasticsearch: which store fits

This table compares the six vector stores Dify can use for knowledge bases, with the situations where each fits and the operational load it adds. Read each row against your existing platforms, skills and backup tooling, then benchmark the shortlist on your own documents before committing.

StoreWhen it fitsOperational costWhat to confirm
Weaviate (default)Teams that want the stack the Docker Compose deployment already starts, with no extra vector service to addRuns as a container in the Compose stack, so it adds a stateful service to back up and upgrade with the rest of DifyBackup and restore steps for the bundled volume, and sizing for your document count
QdrantTeams that want a dedicated vector service and the store the Dify Enterprise resources checklist namesSeparate service to run; the Enterprise reference uses a three-node Qdrant cluster for productionCluster setup, snapshot process and whether your team can operate it under Enterprise guidance
MilvusTeams with an existing Milvus practice or a need to evaluate it against your own document workloadSeparate, multi-component service to deploy, upgrade and back up; adds the most moving parts in this listCurrent Dify support status for Milvus and the deployment footprint your platform team will accept
pgvectorTeams that want fewer stateful systems by storing vectors in the PostgreSQL database Dify already usesNo new service if PostgreSQL is already run and backed up; vector data grows the database and its backupsIndex type, memory headroom on the database host and how vector backups are scheduled with metadata
OpenSearchOrganizations that already operate OpenSearch clusters with support, monitoring and access controls in placeLow added cost if the cluster exists; otherwise a new cluster to size, secure and patchSupported Dify configuration for your OpenSearch version and the team that owns cluster upgrades
ElasticsearchOrganizations that already run Elasticsearch for search and logging and want one platform to governLow added cost if the cluster exists; licensing and feature tiers vary by deployment, so check before committingLicensing terms for your use, supported Dify configuration and cluster capacity for embeddings
Benchmark on your documentsEvery shortlisted store, before the choice is locked inTest ingestion time, query latency and recall on a representative sample of your own files, not published comparisonsDocument types, chunk sizes, embedding model and the retrieval settings you intend to run in production

How to configure the vector store in Dify step by step

This sequence takes a self-hosted Dify from an unconfigured vector store to a verified knowledge base that returns expected chunks. Each step closes with a check, so problems surface before any real documents are loaded.

  1. Confirm the target version and its variables

    Identify the Dify version you will run and open the self-hosting documentation and release notes for that version before editing anything. Check the environment variable reference for the vector store variable names that version expects, and compare them with the .env.example file shipped in the release you downloaded. Record the chosen version in your change log. You know this step is done when you can name the exact vector store variables and the version they apply to, with the reference open next to your deployment notes.

  2. Decide the vector store before loading content

    Choose the store with your platform, security and operations teams before any knowledge base exists. Weaviate is the default in the Compose stack, and the environment reference lists Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch as options. Consider who will operate the store, whether you already run one of these engines, and how you will back it up. Changing the store later means rebuilding knowledge bases, because document content is not carried over in app exports. You know this step is done when a written decision names the store, its owner and its backup method.

  3. Set the vector store variables and start the stack

    In the deployment directory, set the vector store selector and the connection settings for your chosen store in the .env file, following the names in the environment reference. Keep the values for the store's endpoint and credentials out of shared files and version control. Start the stack with Docker Compose and confirm the store container reports healthy in the container status output. You know this step is done when the store container is running and healthy and the api and worker containers start without configuration errors in their logs.

  4. Confirm connectivity from the api and worker containers

    Test that the api and worker containers can reach the vector store over the Compose network using the same endpoint and credentials Dify uses. Run a simple request from inside each container with the tools available in its image, and inspect the Dify logs for connection or authentication errors. If the store is outside the Compose network, confirm the route, firewall rules and TLS settings from the containers, not only from the host. You know this step is done when both api and worker reach the store and no connection errors appear in their logs during a short observation period.

  5. Create a test knowledge base with a small document set

    In the Dify console, create a knowledge base using a small set of non-sensitive documents with known content, such as a few short files where you can predict the answers. Choose the embedding model you intend to use in production, since the stored vectors depend on it. Let indexing finish and check the indexing status in the console. Then confirm in the vector store, using its own administration tools, that a collection or index for this knowledge base was created and holds the expected number of entries. You know this step is done when indexing completes without errors and the store shows the new collection with entries.

  6. Run retrieval and verify expected chunks

    Run test queries against the knowledge base from the Dify retrieval test feature, using questions whose correct source passages you already know. Review the returned chunks, their scores and their source documents, and compare them with your expected answers. Adjust chunk size and retrieval settings only after you have a baseline, and rerun the same queries after each change. Note which settings you used, since they belong in your configuration record. You know this step is done when the known questions return the expected source chunks consistently across repeated runs.

  7. Record the configuration and back up before scaling

    Document the store choice, version, variable names (without secret values), embedding model, and retrieval settings that produced the passing test. Take a backup of the stack configuration and the vector store data according to your operations plan, and confirm the backup can be restored in a test environment before you load production content. Repeat the backup before each Dify upgrade, following the upgrade guidance for the target version. You know this step is done when the configuration record exists and a restore test of the store has been completed successfully.

How documents and queries flow through the vector store

The diagram starts with two paths that meet at the vector store. An uploaded document is saved to object storage, then the worker splits it into chunks, calls an embedding model through the SSRF proxy, and writes vectors to the vector store while document metadata goes to PostgreSQL. A user query goes through the api, is embedded with the same model, runs a similarity search, and returns matching chunks to the model. Check that the embedding model used at query time matches the one used at indexing, and that the proxy allows the embedding endpoint you intend to use.

Document indexing and query retrieval share one vector store and one embedding model.

Vector store setup for Compose, Kubernetes and air-gapped deployments

The Community edition Docker Compose stack includes Weaviate as the default vector store, so a first deployment on the default settings needs no separate vector database build. The stack also starts PostgreSQL, Redis, Nginx, the api and worker services, a code sandbox and an SSRF proxy, which means Weaviate is one more container your team must patch, back up and monitor.

  • Default path: Weaviate runs as a container in the same stack, so the first knowledge base works without a separate vector service.
  • Alternative stores: Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch are selectable through the vector store setting, but you configure the external store and its connection yourself.
  • Ownership: Any store you add becomes your responsibility for storage sizing, backups, version pinning and monitoring after go-live.
  • Backup scope: Plan a backup of the vector data alongside the PostgreSQL and file storage backups taken before each upgrade.
  • Resource headroom: The documented minimum of 2 CPU cores and 4 GB of RAM covers the stack, so size the host for the vector store's own memory needs.

Before committing, confirm with the vendor and your own tests which store, version and connection settings the Community edition supports. Check the current variable names in the Dify environment variable reference.

What drives vector database effort and cost, and how to keep it down

This table lists the factors that change the effort and cost of running the vector store behind Dify knowledge bases, who pays for each one, and whether it is one-time or recurring. Read it before scoping, then ask a partner to price each driver separately in the written quote.

DriverWho pays and one-time or recurringHow to keep it down
Document volume and update frequencyInfrastructure is recurring; initial ingestion and chunking is one-time, while ongoing sync of changed documents is recurringStart with the documents that answer real questions, and set a clear refresh schedule instead of continuous re-ingestion
Number of knowledge bases and workspacesSetup effort is paid per knowledge base; each workspace adds configuration and access review that recursScope fewer knowledge bases in the first phase and add others once the first set is tested
Choice of store and whether it is clusteredClustered stores add infrastructure and operations cost that recurs; the Dify Enterprise checklist calls for a three-node Qdrant cluster in its production examplePick a store the team already runs and can back up, and only cluster it when availability requirements demand it
Number of environments (dev, test, production)Each environment needs its own store, ingestion run and retrieval tests, which recurs as infrastructure and test effortUse a smaller sample dataset in non-production and script environment setup so it can be rebuilt quickly
Embedding model changes that force re-indexingRe-embedding every document is a one-time cost paid again for each model change, including model usage chargesFreeze the embedding model before go-live, and script re-indexing so it can run without manual steps
Compliance requirements for evidence and backupsEvidence collection and backup testing are recurring effort paid by the client's compliance and operations teams or by the partner if contractedDefine which backups, restore tests and access logs are needed before build, and confirm them against the assessor's expectations
Migration between storesA move from one store to another is a one-time project cost covering re-ingestion, retrieval retesting and cutoverChoose the store early and document chunking and retrieval settings so a later move can reuse them

How to tune retrieval settings and migrate between stores

Tune retrieval before you commit to a store, because the settings you choose determine what the model sees and they carry over to any replacement index. For each knowledge base, the team will decide how documents are split into chunks, how many chunks are returned per query, whether a minimum relevance score filters weak matches, and whether retrieval uses vector search alone or combines it with keyword search and a reranking step. Chunk size and overlap usually matter more than the choice between two capable stores, so test them on a set of real questions drawn from your users. Dify's knowledge base and app documentation lists the exact setting names, their defaults and which ones apply to a given retrieval mode. Confirm those names against the version you deploy, since the configuration screens change between releases. Record the values you settle on with the test results, so a later change can be compared against a known baseline.

Plan for migration from the start, because a YAML DSL export does not carry knowledge base content or embeddings. The export keeps app configuration, workflow nodes, prompts and the links to knowledge bases, but the documents and their vectors must be rebuilt in the target store. Switching from one vector store to another therefore means re-indexing from source files. Keep the original documents in object storage that you control, not only inside the Dify upload flow, so the rebuild does not depend on any one instance. Also record which embedding model produced each index, its version and its dimension count. A vector store cannot mix vectors from different embedding models, so a change of model forces a full re-embed even when the store stays the same. Run a sample re-index into the new store and compare answers to your test questions before you switch the apps over.

Secure the vector store and the data it holds

The vector store holds embedded copies of your knowledge base documents, so it needs the same protection as the source files. The controls below cover who can reach the store, how its credentials are handled, what the Dify secret key protects, how backups are encrypted, and where outbound traffic goes. Confirm each one against the store you select, because feature support differs between Weaviate, Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch.

Limit network placement to Dify services

Place the vector store on the internal Docker network or private subnet so that only the api and worker services can open connections to it. Do not publish its port on the host or on a public load balancer. In the default Compose stack, Weaviate runs alongside the other core services, so confirm which ports the compose file exposes before you change anything. Test reachability from a machine outside the Dify network and expect it to fail.

Compose deployment docs

Enable authentication on the store

Confirm whether your chosen store supports API keys, basic authentication or role-based access for the client connection, and whether that setting is on by default. Some deployments run a store with no authentication inside a trusted network, which means any container on that network can read or delete vectors. Record the authentication method for each store in your design document, and test that an unauthenticated request is rejected.

Keep store credentials out of plain files

Store connection settings belong in the environment file or a secret manager, not in committed configuration, shell history or the Dify console. Restrict read access to the .env file on the host and confirm that backup jobs and log collectors do not copy it. Rotate the store credential on a schedule you define, and plan the restart of api and worker services that rotation requires.

Environment variable reference

Plan around SECRET_KEY

The SECRET_KEY signs session cookies and JWTs and encrypts OAuth credentials, so generate it once, store it in a secret manager and back it up with the rest of the configuration. Changing it after deployment logs out all users. Changing it can also leave stored OAuth credentials unreadable, so confirm the effect in your version's documentation before any rotation. Treat it as a change that needs a maintenance window.

Encrypt and restrict store backups

Vector data is derived from your documents, so a backup of the store can expose the same content. Confirm whether your store supports encryption at rest for its data directory or snapshots, and where its snapshots are written. Restrict access to the backup bucket or volume to the operators who run restores, and log restore actions. Test a restore into a separate environment before you rely on the backup.

Route outbound traffic through SSRF_PROXY

Configure SSRF_PROXY settings so that outbound requests from Dify, including web content fetched for knowledge base ingestion, pass through a proxy that blocks internal and private IP ranges. This keeps a crafted URL from reaching the vector store or other internal services. Confirm that the store's own endpoints sit on an address the proxy does not need to reach, and test the block with a request to a private address.

How to verify retrieval works and fails safely

Treat retrieval as something to prove before go-live, not something to assume from a successful upload. Start with a fixed question set in which each question has one or more expected source documents, then run every question against the chosen store and record which chunks come back and whether the expected document ranks in the results Dify passes to the model. The question set should come from the business owners who will use the knowledge base, because they know which questions matter and which answers are wrong. Answer quality also depends on your documents, chunking choices and the model you pair with retrieval, so a passing retrieval test does not certify the final answer. Keep the question set and its expected sources under version control so the same test can be repeated after a store change, an embedding model change or a Dify upgrade.

Next, test whether the index survives a restart. Upload a known set of documents, confirm retrieval, then recreate the containers for the vector store and the Dify services, not just restart them, and run the fixed question set again. Vector data must sit on a persistent volume that the recreated container mounts, so confirm the volume name and location in your Compose file before the test. Then run a deliberate store outage by stopping the vector store container and sending a question through a workflow or app that uses the knowledge base. Check what the user sees and what lands in the logs. The error should be a generic failure message, the app should not hang indefinitely, and neither the response nor the logs should expose internal hostnames, ports, container names or stack traces. Finally, delete a document from the knowledge base and confirm its vectors are gone from the store, since a document that disappears from the console but still answers questions is a data exposure risk. Confirm the exact deletion behavior for your chosen store with the vendor documentation and your own environment.

Questions buyers ask before choosing a vector store for Dify

Can we keep the default Weaviate for our Dify knowledge bases?

Yes, in most cases the default is a reasonable starting point, because the self-hosted Docker Compose stack already includes Weaviate. The Dify environment reference lists Weaviate as the default vector store, with Qdrant, Milvus, pgvector, OpenSearch and Elasticsearch as alternatives. Keeping the default avoids extra services to run, but you still need to size its storage and memory against your document set, back it up with the rest of the stack, and confirm it meets your retention and access rules. Ask your team to test retrieval quality on your own documents before committing, since the store choice matters less than chunking, embedding model and retrieval settings. If your standards require a specific store, such as one already in your approved platform list, that decision should come before the build.

Is pgvector enough for our document volume?

It depends on the number of chunks, query load and how often you reindex, so the answer comes from testing rather than a rule of thumb. pgvector stores vectors in PostgreSQL, which Dify already uses for its metadata, so it reduces the number of services to operate and back up. The trade-off is that vector search shares database resources with the application, so heavy indexing or query traffic can affect the rest of Dify. Dedicated stores such as Qdrant or Milvus are built for vector workloads and scale out differently. Before deciding, measure your expected chunk count, index build time and query latency against a representative sample, and confirm the pgvector version and index type you plan to use with your database team.

How much effort is a vector store migration, and what drives it?

Effort is driven mainly by how many knowledge bases and documents you have, how they were chunked, and whether the new store uses the same embedding model. Dify app exports do not include knowledge base content, so vectors and documents generally have to be re-ingested into the new store rather than copied across. Work includes configuring the new store in the environment settings, reindexing each knowledge base, re-running retrieval tests against your question set, and updating any apps that depend on specific collections. Cost rises with document volume, the number of embedding model changes, and the number of teams who must re-verify answers. Ask for a written migration plan that lists each knowledge base, the rollback method and the verification steps before work starts.

Can our own team select and configure the vector store without a partner?

Yes, a capable platform team can do this internally, especially for the default store or pgvector on an existing PostgreSQL service. The work is mostly configuration and testing: setting the vector store variables in the environment file, sizing the chosen service, indexing sample documents, and tuning retrieval settings. Teams without vector database experience often underestimate retrieval evaluation, backup and restore testing, and the effect of changing embedding models later. A partner is most useful when the store must be clustered, when several Dify environments need the same design, or when security and compliance reviewers need documented evidence. DeployOpen works on fixed-scope engagements agreed in writing, so you can decide which parts to keep in-house.

What does the work need from our side?

The work needs four inputs from your side: representative documents, a test question set with expected sources, a named owner for the embedding model, and access to the infrastructure where Dify runs. Documents should cover the formats and sizes your users actually upload, so chunking and indexing are tested realistically. The question set lets you compare stores and settings with the same measures, and it should include questions that must return the right source and questions that must refuse to answer. The embedding model owner decides which model is used, since changing it later means reindexing. Infrastructure access covers the Docker or Kubernetes host, network paths to the store, and backup storage. Ask for the exact list in the written scope.

How long does choosing and setting up a vector store take?

The duration depends on the number of stores you compare, the size of your document set, whether you need a clustered deployment, and how many reviews your security and compliance teams require. A single-store setup on the default or pgvector with a small document set is usually a short exercise, while a comparison across several stores with a formal retrieval evaluation takes longer. Clustered stores add time for network design, storage sizing and failover testing. No duration is given here because it is not supported by a researched fact for this topic. DeployOpen states timelines in the written scope after reviewing your documents, environment and review requirements, so ask for a timeline with milestones rather than a single estimate.

Which retrieval settings should we check after choosing a store?

Check the settings that control what the model receives: chunk size and overlap, the number of results returned, any reranking step, and score thresholds that filter weak matches. Each store can return results differently, so the same settings may produce different context on Weaviate, Qdrant or pgvector. Test these settings against your question set and record which source each answer cites. Also confirm that metadata filters work for your access rules, so users only retrieve documents they are allowed to see. Keep the tested configuration in version control with the environment file, so the same settings are restored after an upgrade or a store change.

How DeployOpen scopes, builds and hands over Dify vector store work

DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside the client's own infrastructure, including the vector store behind Dify knowledge bases. Store selection, sizing and retrieval settings are agreed in writing before any build starts, so the choice can be reviewed by the security and platform teams who will run it.

How we scope

  • Written scope covers the candidate stores, the data volumes and document types to be indexed, and the retrieval settings to be tested.
  • Scope records which knowledge bases must move later and which stores the client's own data residency rules allow.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts. Quotes follow from that scope.

How we build

  • Deploy the chosen store in the client's cloud account, data center or air-gapped network, alongside the Dify Docker Compose or Kubernetes stack.
  • Load representative knowledge bases, then test retrieval quality, latency and index rebuild behavior against the agreed settings.
  • Verify credentials, network paths between Dify services and the store, and backup and restore for the vector data.

How we hand over

  • Documentation of the store decision, configuration keys, sizing assumptions and the test results behind them.
  • Runbook for adding a store, migrating knowledge bases between stores and reindexing after an embedding model change.
  • Walkthrough with the engineers who will operate the stack, so ownership of upgrades and capacity checks is clear.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers, covering vector store changes alongside Dify minor releases.
  • Retainer work can include rechecking retrieval settings when document volume grows or the Dify release notes change the store integration.
  • Confirm response times, covered versions and out-of-hours terms in the written retainer scope before signing.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.