ensureCollection

abstract suspend fun ensureCollection(name: String, configure: CreateCollectionBuilder.() -> Unit): Boolean

Create the collection if it is missing, and otherwise check that the one already there is the one asked for — the primitive a rerunnable bootstrap script needs.

qdrant.ensureCollection("docs") { vector { size = 768; distance = Distance.COSINE } }

The check compares only what configure actually asked for: the dense vector names with their size and distance, and the sparse vector names. Everything the server fills in by default (HNSW, optimizers, quantization) is left alone, so a collection tuned after creation still passes. Read getCollection for the full stored config.

A mismatch fails loudly rather than being ignored, because the alternative is an application that starts up and only discovers the wrong vector size on its first upsert.

Return

true if this call created the collection, false if it was already there.

Throws

if the existing collection's vectors differ from the requested ones, or the server returned no config to check against.