litedb-org/LiteDB · critical · LiteException
0
0
Error message
Vector data block is corrupted.
What it means
Thrown by VectorIndexService.ReadExternalVector when a byte slice read from the vector data block has a length not aligned to 4 bytes (sizeof(float)). Vector data is floats, so any non-multiple-of-4 region indicates the stored vector data block is byte-level corrupted or was truncated mid-float.
Source
Thrown at LiteDB/Engine/Services/VectorIndexService.cs:722
return Array.Empty<float>();
}
var totalBytes = dimensions * sizeof(float);
var vector = new float[dimensions];
var bytesCopied = 0;
foreach (var slice in this.GetVectorDataService().Read(node.ExternalVector))
{
if (bytesCopied >= totalBytes)
{
break;
}
var available = Math.Min(slice.Count, totalBytes - bytesCopied);
if ((available & 3) != 0)
{
throw new LiteException(0, "Vector data block is corrupted.");
}
Buffer.BlockCopy(slice.Array, slice.Offset, vector, bytesCopied, available);
bytesCopied += available;
}
if (bytesCopied != totalBytes)
{
throw new LiteException(0, "Vector data block is incomplete.");
}
return vector;
}
private PageAddress StoreVector(float[] vector)
{
if (vector.Length == 0)
{View on GitHub (pinned to f906a5f850)
Solutions
- Restore the database from a known-good backup.
- Run db.Rebuild() (full checkpoint + rebuild) to drop/recreate indexes; then recreate the vector index.
- Ensure clean shutdowns and that no external process touches the .db/-log files while open.
- Enable and verify WAL checkpoint completion before backups.
Example fix
// before - read hits corrupted vector pages
var v = collection.VectorFind("emb", query);
// after - rebuild indexes then retry
using var db = new LiteDatabase("app.db");
db.Rebuild(); // rebuilds/drops corrupt indexes
collection.EnsureVectorIndex("emb", 128); Defensive patterns
Strategy: try-catch
Try / catch
try { var results = collection.VectorFind("emb", q); }
catch (LiteException ex) when (ex.Message.Contains("Vector data block is corrupted")) {
// rebuild vector index, then retry or report
collection.DropIndex("emb"); collection.EnsureVectorIndex("emb", dims);
} Prevention
- Keep backups and run db.Rebuild() after suspected corruption.
- Prevent external processes from touching open .db files.
- Ensure clean shutdowns so WAL checkpoints complete.
When it happens
Trigger: Reading a vector index node whose external vector data pages were corrupted: physical disk corruption, a partial/unflushed write, an interrupted checkpoint, or a file edited outside LiteDB. Also possible after a version/format mismatch in the vector index layout.
Common situations: Power loss or process kill during a vector index write without WAL recovery; copying a .db file while open; storage hardware errors; upgrading across incompatible vector-index formats; concurrent manual file access.
Related errors
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/db64a66c24890932.
Report an issue: GitHub.