Optimizer

Qdrant stores the points of a collection in one or more shards, and each shard divides its points into segments. Each segment has its own vector storage, payload storage, vector and payload indexes, and ID tracker. There are two types of segments: appendable and non-appendable. Appendable segments accept new points, while non-appendable segments only support reads and deletes.

For efficiency reasons, Qdrant, like many databases, applies data changes in batches rather than one point at a time. Some of its data structures, such as vector indexes, are hard to update in place, so Qdrant rebuilds them in the background when needed, or when you call optimize on Qdrant Edge.

The optimizer handles these rebuilds and works at the segment level. It selects one or more segments that can be improved and rebuilds them into a single new segment, for example to index it, compact it, or reduce the number of segments. The segments being optimized remain readable while the rebuild is in progress. To keep them available, Qdrant wraps each segment in a proxy that transparently handles data changes. The proxy writes changed data to a copy-on-write segment, which has priority for retrieval and subsequent updates.

Qdrant has four optimizers, described in the following sections. In each round of optimization, at most one optimizer selects a given segment. Every rebuild removes deleted points and applies the current collection configuration, whichever optimizer selected the segment.

Indexing Optimizer

The indexing optimizer builds a vector index for a segment once its vector data exceeds the indexing threshold. New points go to an appendable segment, which has no vector index. While a segment is small, a full scan is fast, and building an index would cost more than it saves. As the segment grows, scans get slower and an index starts to pay off.

A full appendable segment without an index is rebuilt as an indexed segment that is no longer appendable.
The appendable segment grows until it crosses the indexing threshold. The indexing optimizer then builds an HNSW index for it, and a new appendable segment takes the new points.

The indexing optimizer also moves vectors to disk when their memory placement requires it, converts large sparse vector indexes from their mutable in-memory form to an immutable form, and rebuilds segments that hold deferred points.

The indexing_threshold parameter sets the indexing threshold, in kilobytes. For example, to set it for an existing collection:

PATCH /collections/{collection_name}
{
    "optimizers_config": {
        "indexing_threshold": 10000
    }
}
curl -X PATCH http://localhost:6333/collections/{collection_name} \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "optimizers_config": {
        "indexing_threshold": 10000
    }
  }'
client.update_collection(
    collection_name="{collection_name}",
    optimizers_config=models.OptimizersConfigDiff(indexing_threshold=10000),
)
client.updateCollection("{collection_name}", {
  optimizers_config: {
    indexing_threshold: 10000,
  },
});
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};

client
    .update_collection(
        UpdateCollectionBuilder::new("{collection_name}").optimizers_config(
            OptimizersConfigDiffBuilder::default().indexing_threshold(10000),
        ),
    )
    .await?;
import io.qdrant.client.grpc.Collections.OptimizersConfigDiff;
import io.qdrant.client.grpc.Collections.UpdateCollection;

client
    .updateCollectionAsync(
        UpdateCollection.newBuilder()
            .setCollectionName("{collection_name}")
            .setOptimizersConfig(
                OptimizersConfigDiff.newBuilder().setIndexingThreshold(10000).build())
            .build())
    .get();
using Qdrant.Client;
using Qdrant.Client.Grpc;

await client.UpdateCollectionAsync(
	collectionName: "{collection_name}",
	optimizersConfig: new OptimizersConfigDiff { IndexingThreshold = 10000 }
);
import (
	"context"

	"github.com/qdrant/go-client/qdrant"
)

client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{
	CollectionName: "{collection_name}",
	OptimizersConfig: &qdrant.OptimizersConfigDiff{
		IndexingThreshold: qdrant.PtrOf(uint64(10000)),
	},
})

Vacuum Optimizer

The vacuum optimizer helps manage storage by handling deleted points. When you delete a point, Qdrant doesn’t remove it right away but marks it as deleted, to avoid slow disk operations during queries. While this improves performance, over time, these marked points can build up, wasting memory and slowing down the system.

The vacuum optimizer solves this problem by permanently removing marked points and reorganizing storage. This cleanup saves memory, especially when large amounts of deleted data build up in the database.

A segment with 20 points, five of them marked as deleted, is rebuilt as a new segment with the 15 remaining points.
Deleted points are initially only marked as deleted. Once the fraction of deleted points in a segment exceeds the deleted_threshold, the vacuum optimizer rebuilds the segment without them.

Two parameters control when the optimizer runs:

  • deleted_threshold sets the minimum fraction of deleted points in a segment required to initiate optimization. For example, a value of 0.2 means that more than 20% of a segment’s points must be marked as deleted for the optimizer to consider running.
  • vacuum_min_vector_number specifies the minimum number of points a segment must contain to qualify for optimization. For example, a value of 1000 ensures that only segments with at least 1,000 points are optimized.
  • Both parameters also apply to each vector index in a segment, counting vectors deleted from points that still exist.

When a segment meets these criteria, the optimizer rebuilds it without the deleted points.

To set these parameters for an existing collection:

PATCH /collections/{collection_name}
{
    "optimizers_config": {
        "deleted_threshold": 0.2,
        "vacuum_min_vector_number": 1000
    }
}
curl -X PATCH http://localhost:6333/collections/{collection_name} \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "optimizers_config": {
        "deleted_threshold": 0.2,
        "vacuum_min_vector_number": 1000
    }
  }'
client.update_collection(
    collection_name="{collection_name}",
    optimizers_config=models.OptimizersConfigDiff(
        deleted_threshold=0.2,
        vacuum_min_vector_number=1000,
    ),
)
client.updateCollection("{collection_name}", {
  optimizers_config: {
    deleted_threshold: 0.2,
    vacuum_min_vector_number: 1000,
  },
});
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};

client
    .update_collection(
        UpdateCollectionBuilder::new("{collection_name}").optimizers_config(
            OptimizersConfigDiffBuilder::default()
                .deleted_threshold(0.2)
                .vacuum_min_vector_number(1000),
        ),
    )
    .await?;
import io.qdrant.client.grpc.Collections.OptimizersConfigDiff;
import io.qdrant.client.grpc.Collections.UpdateCollection;

client
    .updateCollectionAsync(
        UpdateCollection.newBuilder()
            .setCollectionName("{collection_name}")
            .setOptimizersConfig(
                OptimizersConfigDiff.newBuilder()
                    .setDeletedThreshold(0.2)
                    .setVacuumMinVectorNumber(1000)
                    .build())
            .build())
    .get();
using Qdrant.Client;
using Qdrant.Client.Grpc;

await client.UpdateCollectionAsync(
	collectionName: "{collection_name}",
	optimizersConfig: new OptimizersConfigDiff
	{
		DeletedThreshold = 0.2,
		VacuumMinVectorNumber = 1000
	}
);
import (
	"context"

	"github.com/qdrant/go-client/qdrant"
)

client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{
	CollectionName: "{collection_name}",
	OptimizersConfig: &qdrant.OptimizersConfigDiff{
		DeletedThreshold:      qdrant.PtrOf(0.2),
		VacuumMinVectorNumber: qdrant.PtrOf(uint64(1000)),
	},
})

Merge Optimizer

Qdrant uses the merge optimizer to manage the number of segments in its storage system, ensuring efficient data organization and query performance.

Qdrant requires at least one small segment to handle frequently updated data efficiently. However, having too many small segments can harm search performance. To address this, the merge optimizer reduces the number of segments when there are more than optimal.

The default_segment_number parameter specifies the target number of segments. Its default depends on the number of available CPUs. When there are more segments than this target, the optimizer merges the smallest segments into larger ones, without exceeding the maximum segment size.

Four small segments with five points each are merged into one segment with all 20 points.
The shard has more segments than the target, so the merge optimizer rebuilds the smallest ones as a single new segment.

To prevent oversized segments that could slow down indexing, the max_segment_size parameter sets a limit on segment size, in kilobytes. Larger segments may improve search performance but can take longer to index. Use this parameter to balance indexing speed against search efficiency, especially with large datasets. When max_segment_size is unset, the limit scales with the number of available CPUs, so it differs between machines. Set it explicitly when you need a predictable segment size.

To set these parameters for an existing collection:

PATCH /collections/{collection_name}
{
    "optimizers_config": {
        "default_segment_number": 4,
        "max_segment_size": 1000000
    }
}
curl -X PATCH http://localhost:6333/collections/{collection_name} \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "optimizers_config": {
        "default_segment_number": 4,
        "max_segment_size": 1000000
    }
  }'
client.update_collection(
    collection_name="{collection_name}",
    optimizers_config=models.OptimizersConfigDiff(
        default_segment_number=4,
        max_segment_size=1000000,
    ),
)
client.updateCollection("{collection_name}", {
  optimizers_config: {
    default_segment_number: 4,
    max_segment_size: 1000000,
  },
});
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};

client
    .update_collection(
        UpdateCollectionBuilder::new("{collection_name}").optimizers_config(
            OptimizersConfigDiffBuilder::default()
                .default_segment_number(4)
                .max_segment_size(1000000u64),
        ),
    )
    .await?;
import io.qdrant.client.grpc.Collections.OptimizersConfigDiff;
import io.qdrant.client.grpc.Collections.UpdateCollection;

client
    .updateCollectionAsync(
        UpdateCollection.newBuilder()
            .setCollectionName("{collection_name}")
            .setOptimizersConfig(
                OptimizersConfigDiff.newBuilder()
                    .setDefaultSegmentNumber(4)
                    .setMaxSegmentSize(1000000)
                    .build())
            .build())
    .get();
using Qdrant.Client;
using Qdrant.Client.Grpc;

await client.UpdateCollectionAsync(
	collectionName: "{collection_name}",
	optimizersConfig: new OptimizersConfigDiff
	{
		DefaultSegmentNumber = 4,
		MaxSegmentSize = 1000000
	}
);
import (
	"context"

	"github.com/qdrant/go-client/qdrant"
)

client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{
	CollectionName: "{collection_name}",
	OptimizersConfig: &qdrant.OptimizersConfigDiff{
		DefaultSegmentNumber: qdrant.PtrOf(uint64(4)),
		MaxSegmentSize:       qdrant.PtrOf(uint64(1000000)),
	},
})

Config Mismatch Optimizer

When you update collection parameters, existing segments keep the configuration they were built with. The config mismatch optimizer finds segments whose configuration no longer matches the collection configuration and rebuilds them with the new settings.

A plain segment built with configuration 1 is rebuilt as a hatched segment with configuration 2 after a configuration change.
After a change to the HNSW configuration, new segments are indexed with the new configuration, and the config mismatch optimizer rebuilds older segments one at a time, largest first.

The optimizer rebuilds a segment when any of the following differs from the collection configuration:

Each rebuild is a full optimization of the segment, so changing these parameters on a large collection can cause a long period of optimization activity.

This optimizer has no configuration parameters.

Optimizer Configuration

You can configure optimizer parameters per collection at creation time, or update them later. For example:

PATCH /collections/{collection_name}
{
    "optimizers_config": {
        "indexing_threshold": 10000
    }
}
curl -X PATCH http://localhost:6333/collections/{collection_name} \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "optimizers_config": {
        "indexing_threshold": 10000
    }
  }'
client.update_collection(
    collection_name="{collection_name}",
    optimizers_config=models.OptimizersConfigDiff(indexing_threshold=10000),
)
client.updateCollection("{collection_name}", {
  optimizers_config: {
    indexing_threshold: 10000,
  },
});
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};

client
    .update_collection(
        UpdateCollectionBuilder::new("{collection_name}").optimizers_config(
            OptimizersConfigDiffBuilder::default().indexing_threshold(10000),
        ),
    )
    .await?;
import io.qdrant.client.grpc.Collections.OptimizersConfigDiff;
import io.qdrant.client.grpc.Collections.UpdateCollection;

client
    .updateCollectionAsync(
        UpdateCollection.newBuilder()
            .setCollectionName("{collection_name}")
            .setOptimizersConfig(
                OptimizersConfigDiff.newBuilder().setIndexingThreshold(10000).build())
            .build())
    .get();
using Qdrant.Client;
using Qdrant.Client.Grpc;

await client.UpdateCollectionAsync(
	collectionName: "{collection_name}",
	optimizersConfig: new OptimizersConfigDiff { IndexingThreshold = 10000 }
);
import (
	"context"

	"github.com/qdrant/go-client/qdrant"
)

client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{
	CollectionName: "{collection_name}",
	OptimizersConfig: &qdrant.OptimizersConfigDiff{
		IndexingThreshold: qdrant.PtrOf(uint64(10000)),
	},
})

Self-hosted Qdrant also supports setting global defaults for all collections in the configuration file. Qdrant applies these defaults when it creates a collection, so changing them doesn’t affect existing collections. For example:

storage:
  performance:
    # CPU budget, how many CPUs (threads) to allocate for an optimization job.
    # If 0 - auto selection, keep 1 or more CPUs unallocated depending on CPU size
    # If negative - subtract this number of CPUs from the available CPUs.
    # If positive - use this exact number of CPUs.
    optimizer_cpu_budget: 0

  optimizers:
    # The minimal fraction of deleted vectors in a segment, required to perform segment optimization
    deleted_threshold: 0.2

    # The minimal number of vectors in a segment, required to perform segment optimization
    vacuum_min_vector_number: 1000

    # Target amount of segments optimizer will try to keep.
    # Real amount of segments may vary depending on multiple parameters:
    #  - Amount of stored points
    #  - Current write RPS
    #
    # It is recommended to select default number of segments as a factor of the number of search threads,
    # so that each segment would be handled evenly by one of the threads.
    # If `default_segment_number = 0`, will be automatically selected by the number of available CPUs
    default_segment_number: 0

    # Do not create segments larger than this size (in KiloBytes).
    # Large segments might require disproportionately long indexation times,
    # therefore it makes sense to limit the size of segments.
    #
    # If indexation speed have more priority for your - make this parameter lower.
    # If search speed is more important - make this parameter higher.
    # Note: 1Kb = 1 vector of size 256
    # If not set, will be automatically selected considering the number of available CPUs.
    max_segment_size_kb: null

    # Maximum size (in KiloBytes) of vectors allowed for plain index.
    # Default value based on experiments and observations.
    # Note: 1Kb = 1 vector of size 256
    # To explicitly disable vector indexing, set to `0`.
    # If not set, the default value will be used.
    indexing_threshold_kb: 10000

    # Max number of threads (jobs) for running optimizations per shard.
    # Note: each optimization job will also use `max_indexing_threads` threads by itself for index building.
    # If null - have no limit and choose dynamically to saturate CPU.
    # If 0 - no optimization threads, optimizations will be disabled.
    max_optimization_threads: null

Optimizer Resource Usage

Three settings control how much CPU the optimizer uses:

  • optimizer_cpu_budget: the number of CPUs available to all optimization jobs on a node. By default, Qdrant leaves one or more CPUs free, depending on the number of CPUs. Set it in the Cloud Console or in the configuration file under storage.performance.
  • max_optimization_threads: the maximum number of optimization jobs that run in parallel per shard. By default, there’s no limit other than optimizer_cpu_budget.
  • max_indexing_threads: the number of threads each optimization job uses to build the HNSW index. Set it in the HNSW configuration. By default, it depends on the number of available CPUs.

For guidance on balancing optimization against search load, see Troubleshoot Read-Write Contention.

Prevent Reads from Large Unindexed Segments

Available as of v1.17.1.

Sometimes a collection receives a high volume of updates, for example, during nightly batch updates or while processing a backlog of updates after a period of downtime. The optimizer might then be unable to index new points fast enough to keep up. When this happens, searches may slow down, because Qdrant has to scan large amounts of unindexed data for every query.

To address this, Qdrant supports querying indexed data only, by setting indexed_only to true. A side effect of searching indexed data only is that it can cause recently updated data to temporarily disappear from search results until Qdrant indexes it again (blinking points).

To mitigate this, Qdrant supports a prevent_unoptimized mode. When it’s enabled, Qdrant accepts and durably stores points written to an unindexed segment that is larger than indexing_threshold (or max_segment_size, if that’s set and smaller), but does not return them in search results. These deferred points only become visible after the optimizer has indexed the segment.

You can enable prevent_unoptimized per collection, or globally in the configuration file.

PATCH /collections/{collection_name}
{
    "optimizers_config": {
        "prevent_unoptimized": true
    }
}
curl -X PATCH http://localhost:6333/collections/{collection_name} \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "optimizers_config": {
        "prevent_unoptimized": true
    }
  }'
client.update_collection(
    collection_name="{collection_name}",
    optimizers_config=models.OptimizersConfigDiff(prevent_unoptimized=True),
)
client.updateCollection("{collection_name}", {
  optimizers_config: {
    prevent_unoptimized: true,
  },
});
use qdrant_client::qdrant::{OptimizersConfigDiffBuilder, UpdateCollectionBuilder};

client
    .update_collection(
        UpdateCollectionBuilder::new("{collection_name}").optimizers_config(
            OptimizersConfigDiffBuilder::default().prevent_unoptimized(true),
        ),
    )
    .await?;
import io.qdrant.client.grpc.Collections.OptimizersConfigDiff;
import io.qdrant.client.grpc.Collections.UpdateCollection;

client
    .updateCollectionAsync(
        UpdateCollection.newBuilder()
            .setCollectionName("{collection_name}")
            .setOptimizersConfig(
                OptimizersConfigDiff.newBuilder().setPreventUnoptimized(true).build())
            .build())
    .get();
using Qdrant.Client;
using Qdrant.Client.Grpc;

await client.UpdateCollectionAsync(
	collectionName: "{collection_name}",
	optimizersConfig: new OptimizersConfigDiff { PreventUnoptimized = true }
);
import (
	"context"

	"github.com/qdrant/go-client/qdrant"
)

client.UpdateCollection(context.Background(), &qdrant.UpdateCollection{
	CollectionName: "{collection_name}",
	OptimizersConfig: &qdrant.OptimizersConfigDiff{
		PreventUnoptimized: qdrant.PtrOf(true),
	},
})

With prevent_unoptimized enabled, setting indexed_only to true is not necessary. They are mutually exclusive.

Effect on wait=true

Write requests support a wait parameter that, when set to true, causes the request to return only after the update has been applied and is visible for search. If prevent_unoptimized is enabled, set wait to false to avoid potential timeouts and delays.

This is particularly important for the Python, TypeScript/JavaScript, .NET, and Java clients, which set wait to true by default. The Go and Rust clients and the REST API already default to false, so you don’t need to change anything when using those.

Qdrant processes updates in strict order: it writes each update to the write-ahead log, and the update worker then applies the updates sequentially, preserving this order.

Under normal conditions, a write request with wait=true returns after Qdrant has applied the update to a segment. With prevent_unoptimized enabled, Qdrant holds the response until it has indexed every deferred point, including the current update, and made them visible for search. Depending on the volume of pending updates in the update queue and the speed of the optimizer, this can take a significant amount of time. It will likely lead to timeouts on the client side. If the client times out, Qdrant still stores the update durably and eventually indexes it, but the client will not receive a confirmation for that specific request.

Because the update worker must finish indexing before continuing to consume the queue, a blocked wait=true request also delays all subsequent updates that use wait=true. Updates with wait=false are written to the write-ahead log immediately, but they are not applied until the blocked request unblocks. This head-of-line blocking means that wait=true can stall the entire update pipeline for as long as indexing takes. Use it with caution when prevent_unoptimized is enabled and the cluster is under heavy write load.

A consequence of enabling prevent_unoptimized and setting wait=false is eventual consistency: updates might not be immediately visible. If your application requires a guarantee that the vector will be available for searching immediately after the API responds, you can set wait=true, but be aware of the implications described in this section. Alternatively, you can choose to not enable prevent_unoptimized, but this may lead to slower search performance under heavy write load.

Monitoring Deferred Points

You can check the number of deferred points in a collection in the update_queue section of the response from the collection info API. The same information is also available in telemetry and metrics, enabling dashboards and alerting.

A non-zero deferred point count means the optimizer is processing a backlog. This is expected under heavy write load; monitor the count to confirm that it is decreasing over time.

Optimization Monitoring

Available as of v1.17.0.

The /collections/{collection_name}/optimizations API endpoint returns information about the optimization of a specific collection, including:

  • A summary of optimization activity, with the number of queued optimizations, queued segments, queued points, and idle segments (segments that need no optimization).
  • Details about any currently running optimization, including:
    • the specific optimizer (merge, indexing, vacuum, or config mismatch)
    • its status
    • the segments involved
    • its progress

Optionally, you can use the with query parameter with one or more of the following comma-separated values to retrieve additional information:

  • queued, to return a list of queued optimizations
  • completed, to return a list of completed optimizations. By default, it returns the 16 most recent. Use the completed_limit query parameter to change this number.
  • idle_segments, to return a list of idle segments

For example:

GET /collections/{collection_name}/optimizations?with=queued,completed

Furthermore, the collection info API reports the state of the optimizers in the optimizer_status field. It’s ok when the optimizers are working normally. If an optimization fails, it contains an error message and the collection status turns red.

Web UI

The same information is also available in the Optimizations tab of the Collections interface in the Web UI. For a specific collection, this tab provides an overview of the current optimization status and a timeline of current and past optimization cycles:

The Optimizations tab in Web UI shows progress and a timeline of optimization cycles

Selecting a specific optimization cycle from the timeline provides detailed information about the tasks performed during that cycle, including their durations:

The Optimizations tab in Web UI provides access to detailed information about optimization tasks and their durations

Was this page useful?

Thank you for your feedback! 🙏

We are sorry to hear that. 😔 You can edit this page on GitHub, or create a GitHub issue.