← All topics

Database Internals & Storage · Topic 108

The LSM-Tree (Log-Structured Merge-Tree) for metadata

An LSM-tree is a write-optimized structure: new and updated entries are written to an in-memory component and flushed to disk as sorted immutable segments; background compaction merges segments so that reads don’t have to scan too many files. Vector databases often use an LSM (or LSM-like) store for metadata and payloads—the key–value or document data associated with each point. This topic covers why LSM fits metadata, write/read behavior, and trade-offs.

Summary

  • An LSM-tree is write-optimized: new/updated entries go to an in-memory component and are flushed as sorted immutable segments; background compaction merges segments so reads don’t scan too many files.
  • In a VDB, the vector index holds vectors/IDs; the LSM (or LSM-like) store holds metadata and payloads by point ID for filtering and returning payloads.
  • LSM gives high write throughput; read cost is managed by compaction and columnar or indexed access. Same merge-and-drop-obsolete pattern as classic LSM; optional B-tree for read-heavy metadata.
  • This split—vector index for similarity, LSM for metadata—is common in production vector databases.
  • Practical tip: use LSM when write throughput is high and you can tolerate compaction; use B-tree when read latency is critical and writes are moderate.

Why LSM for metadata

The vector index (e.g. HNSW, IVF) holds only vectors and maybe IDs for the search path; the full metadata and payload are looked up by ID from the LSM store. That keeps the index small and allows filtering and returning payloads without embedding everything in the graph or cluster structure.

Pipeline: point insert/update → write to memtable (in-memory) → when full, flush to sorted segment on disk → background compaction merges segments and drops obsolete keys. Read: lookup by point ID may touch memtable and multiple segments; compaction keeps segment count low so read amplification is bounded.

Write and read behavior

LSM gives high write throughput and good space amplification after compaction; read amplification is managed by merging and columnar or indexed access. This pattern—vector index for similarity, LSM (or similar) for metadata—is common in production vector databases.

Trade-offs: excellent write throughput and append-only write path vs. read cost that depends on segment count and compaction lag. Practical tip: tune compaction (frequency, parallelism) to match write rate so that segment count and read latency stay under control; consider columnar layout for metadata to speed up filtering scans.

Frequently Asked Questions

Is the vector index itself an LSM?

Not usually. The vector index (HNSW, IVF) is a separate structure. LSM is used for the key–value or document store that holds metadata and payloads by point ID.

What if I only store vectors, no metadata?

You might still use a simple append log or LSM for point IDs and vectors if you need durability and updates; or a flat file per segment. LSM is most useful when you have mutable metadata and payloads.

How does compaction work for LSM in a VDB?

Same idea as classic LSM: merge sorted runs, drop obsolete entries (e.g. overwritten or deleted keys), and produce fewer, larger segments. See the compaction topic for details.

Can I use a B-tree instead of LSM for metadata?

Yes. B-trees are read-optimized and update-in-place. LSM is chosen when write throughput is high and you can tolerate periodic compaction; B-tree when you want simpler read path and fewer background tasks.