Milvus Service Guide
Milvus is the vector database a workroom keeps its embeddings in. Core creates
it as a vector DB instance (engine: milvus) from the bundled service-milvus
template. Each instance runs three services: the Milvus server (standalone),
its SeaweedFS object store (seaweedfs), and etcd.
An administrator can size an instance, lift Milvus's flush-rate limit, and turn on memory mapping. Nothing changes unless an administrator sets one of them: by default every service runs with its template's CPU and memory, and Milvus keeps its own defaults.
The Vector DB API
POST /api/context/vectordbs creates an instance, and
PUT /api/context/vectordbs/{id} changes it. Both take the workroom in the
X-Workroom-ID header. For example, a workroom's Milvus sized above the
template, with memory mapping on (for a large collection, see
Memory and Disk for a Large Collection):
curl -sS -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "X-Workroom-ID: $WORKROOM_ID" \
-H "Content-Type: application/json" \
"$KAMIWAZA_URL/api/context/vectordbs" \
-d '{
"name": "milvus-'"$WORKROOM_ID"'",
"engine": "milvus",
"storage_size": "100Gi",
"resources": {
"milvus": {"limits": {"cpu": "4", "memory": "32Gi"}},
"seaweedfs": {"limits": {"cpu": "2", "memory": "4Gi"}},
"etcd": {"limits": {"memory": "2Gi"}}
},
"config": {
"QUERYNODE_MMAP_SCALARFIELD": "true",
"QUERYNODE_MMAP_SCALARINDEX": "true"
}
}'
storage_size sizes both the object store's and Milvus's volumes, which are
1Gi each by default. The response, and GET /api/context/vectordbs/{id}, show
the instance's resources.
With the umbrella chart's default, core.workroom.contextAutoProvisionMode: lazy,
Core creates a workroom's Milvus, named milvus-<workroom-id>, the first time
the workroom needs it, with the template's defaults. To start a workroom with
the settings below, create its Milvus yourself before the workroom's first
upload.
CPU and Memory
resources sets CPU and memory requests and limits, as Kubernetes
quantities such as "4", "500m" or "32Gi", for each of the three
services: milvus for the Milvus server, seaweedfs for its object store and
etcd for its etcd.
| Service | Template limit | Template request |
|---|---|---|
Milvus (standalone) | 1.0 CPU, 2G | 0.05 CPU, 64M |
SeaweedFS (seaweedfs) | 0.5 CPU, 512M | 0.05 CPU, 64M |
etcd (etcd) | 0.5 CPU, 512M | 0.05 CPU, 64M |
A fast import into one vector DB can fill etcd's 512M; give it 2Gi for large
imports. etcd needs Milvus service 2.4.38 or later. An instance on an older
template refuses it with 400, naming the variables the template lacks.
- An instance keeps the Milvus service release it was created with. An
instance created before 1.4.2 refuses
resourceswith400, because its release does not declare them. Recreating it on the bundled release makes it sizable, but a recreated vector DB starts empty: the workroom's files must then be imported again. - A value you leave out keeps the template's own.
- On an update, the
resourcesyou send replace the previous ones, and{}clears them, back to the template's values. Leavingresourcesout of an update keeps them. - A request above its limit, counting the template's own values, is refused
with
400. To request more than a template limit, raise the limit in the same call. - An update applies to the running instance at once: Kubernetes replaces the pods whose values changed. Change it between imports.
- Only an administrator can set
resources. Anyone else gets403(vectordb_resources_requires_admin).
Flush Rate
Core marks a file done only after a flush of the workroom's collection has completed, and only a flush that started after the file's chunks were inserted counts. Milvus allows 0.1 flushes per second per collection by default, one every 10 seconds. Past that, each flush waits for Milvus to allow it.
From 1.4.2, Core shares flushes:
- Concurrent imports: files that are inserted while a flush is due or running wait for the next one, and every file inserted before a flush started is done when that flush completes. While inserts keep arriving less than half a second apart, Core flushes each collection at most once per interval, 10 seconds by default, across all of its processes, which keeps to Milvus's limit. See Vector DB Flushes for the interval setting.
- One-at-a-time imports: when each file starts only after the previous one is done, every file gets its own flush, as before 1.4.2. A lone file is flushed once no other file has arrived for half a second, so it is not held for the interval, but Milvus's limit holds such an import to about one file every 10 seconds per collection.
To speed up a one-at-a-time import, set
QUOTAANDLIMITS_FLUSHRATE_COLLECTION_MAX to "-1" in the instance's config
to lift Milvus's limit. Lift it too if you set Core's interval below 10
seconds, or to 0, which flushes after every file as before 1.4.2. The cost:
more, smaller segments, which Milvus merges in the background. That merging
uses CPU, so give Milvus more CPU with resources when you lift the limit.
Memory Mapping
By default Milvus holds a collection's text and scalar fields, and their
indexes, in memory, so its memory grows with the collection. Set
QUERYNODE_MMAP_SCALARFIELD and QUERYNODE_MMAP_SCALARINDEX to "true" in
the instance's config to map them from disk instead. The text and scalar
fields then no longer add to Milvus's memory.
The vectors stay in memory. Core builds an IVF_FLAT index, which holds every
embedding in memory, and the template has no setting to map vectors from disk.
Milvus's memory therefore still grows with the number of chunks: size its
memory limit for the collection the workroom will reach, and raise it with
resources as the collection grows.
Memory mapping uses one of the kernel's memory-map areas for each mapped file.
A large collection can use more than Linux's default vm.max_map_count of
65530, and Milvus then fails. Raise it on every node that can run Milvus, and
keep it across reboots:
echo 'vm.max_map_count = 1048576' | sudo tee /etc/sysctl.d/90-milvus-max-map-count.conf
sudo sysctl --system
sysctl vm.max_map_count
vm.max_map_count = 1048576
Memory and Disk for a Large Collection
Milvus's template memory limit, 2G, suits a small collection. Its memory grows with the vectors the collection holds (Memory Mapping), and Kubernetes OOM-kills Milvus when it reaches its limit.
In a measured import into one workroom, with text and scalar fields memory-mapped, Milvus held 40.9 GiB at 730 GB of documents. From 500 GB on, it grew about 3.6 GiB for every 50 GB imported. That import gave Milvus 4 CPUs and a 64Gi memory limit. A corpus that splits into more chunks per gigabyte needs more memory for the same size.
Set the memory limit above what the collection will reach, with room for
Milvus's file cache, and raise it with resources as the collection grows. An
update replaces the Milvus pod, so change it between imports.
The collection also needs disk. storage_size sizes the vector DB's volumes,
1Gi each by default (The Vector DB API). In the same import, the vector
DB's two volumes held 129 GB together at 730 GB of documents, 97 GB of it in
its object store, and the instance was created with "storage_size": "300Gi".
Set it when you create the instance: an update cannot change it. To grow it,
recreate the vector DB, which starts empty.
Set Them at Create
Milvus reads the flush-rate and memory-mapping settings when its pod is
created. A later config update stores the new values, but does not restart
the running pod. Set them when you create the instance. For an existing
workroom, that means recreating its vector DB, which starts empty, so plan to
import the workroom's files again.
Core adds each of the three variables to Milvus's environment only when it is
set, and an empty value counts as unset. Left unset, Milvus keeps its own
defaults. Only an administrator can set vector DB config.
Errors That Reach Existing Callers
Requests that worked before 1.4.2 get the same answers:
- A second change waits. A second update or scale
(
PUT /api/context/vectordbs/{id}orPOST /api/context/vectordbs/{id}/scale) of the same instance, while one is in progress, waits for it to finish, up to two minutes, then runs. A config-only or scale change finishes in under a second; a change that resizes the running instance can take longer. configandresourcestogether.configmay name the variablesresourcessets (MILVUS_CPU_REQUEST,MILVUS_CPU_LIMIT,MILVUS_MEMORY_REQUEST,MILVUS_MEMORY_LIMIT, and the same four with aSEAWEEDFS_or aMILVUS_ETCD_prefix). They are stored like anyconfigvalue, and a create's values size the instance without the checksresourcesmakes. When the same request also setsresources, its values win and theconfigentries for those variables are dropped, with a warning in Core's log. Useresourcesto size an instance.