Skip to content

Update DiskANN FFI - #1992

Merged
kevin-montrose merged 80 commits into
mainfrom
users/kmontrose/diskANNFFIUpdates
Sep 25, 2026
Merged

kevin-montrose merged 80 commits into
mainfrom
users/kmontrose/diskANNFFIUpdates

Conversation

@kevin-montrose

@kevin-montrose kevin-montrose commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Making what are (hopefully) the final big FFI changes before stabilization.

  1. Add nint logCallback to create_index
    • logCallback is:
      • void LogCallbackUnmanaged(ulong context, nint logMessage, nuint logMessageLength)
      • context low bits are used to enrich log line on the Garnet side
      • logMessage is utf8 encoded text
      • logMessageLength is the byte count of logMessage
  2. Add valueLengthHint to readCallback
    • Its OK for this to be wrong, but it will impact performance
    • Better to overestimate than underestimate
    • This replaces the ActiveReadGeometry estimates on the Garnet side - allowing DiskANN to own record size information
  3. Use overflow_results(ulong context, nint index, nint continuation, nint output_ids, nuint output_ids_len, nint output_distances, nuint output_distances_len, nint new_continuation)
    • For when search_xxx(...) function can't fit all of the results into the provided output_ids buffer
    • DiskANN can assume we'll call this once per non-null continuation
    • Invoked until we get a null continuation - should be null if an error is encountered
  4. Add byte random_members(ulong context, nint index, uint count, nint output_ids, nuint output_ids_len)
    • Used to implement VRANDMEMBER
    • Gets count random (external) ids and places them in output_ids, length prefixed
    • returns 1 on success, and anything else on failure (will be logged)
  5. Add int search_neighbors(ulong context, nint index, nint id_data, nuint id_len, nint output_ids, nuint output_ids_len, nint output_distances, nuint output_distances_len, nint continuation)
    • This implements VLINKS which is basically "give me the neighbors of an element + distances to each"
    • If buffer is too small, continuation will be set and search can continue with continue_search(...)
  6. Change filter_callback to accept data in place rather than the parsed internal id
  7. Add result return to backfill_quant_vectors
    • Returning 1 is success, anything else is failure (and is logged)
  8. Requires all keys passed to callbacks (from DiskANN to Garnet) must be multiples of 4-bytes in length
  9. Asserts for 8 & that values passed to DiskANN dataCallbacks are 4-byte aligned

@kevin-montrose
kevin-montrose marked this pull request as ready for review September 22, 2026 20:51
Copilot AI balanced review requested due to automatic review settings September 22, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Multiple unresolved critical and moderate correctness, memory-safety, resource-leak, and protocol issues block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 9 High severity · 6 Medium severity · 1 Low severity

Open (16)
What changed in this PR

Updates Garnet’s DiskANN FFI and adds vector neighbor and random-member support.

Changes:

  • Extends callbacks and native signatures for logging, filtering, continuations, neighbors, and random members.
  • Implements VLINKS and VRANDMEMBER across storage, API, RESP, and tests.
  • Updates alignment, quantization, migration, documentation, and DiskANN package dependencies.
File Summary and findings
website/​docs/​dev/​vector-sets.md Documents the expanded DiskANN ABI.
Nit (1 vote): build_quant_table is incorrectly documented as returning void instead of bool.
Nit (1 vote): dataLengthLength should be dataLength.
Nit (1 vote): Correct the whcih typo.
Nit (1 vote): search_exploration_factor should be documented as uint, not int.
Nit (1 vote): Replace the obsolete QuantizationRequested enum name with SuccessStartTraining.
website/​docs/​commands/​vector-sets.md Removes the preview warning.
Nit (4 votes): Add VLINKS and VRANDMEMBER syntax/replies and update support tables and checklists.
test/​standalone/​Garnet.test.vectorset/​VectorSetRecallSmokeTests.cs Adjusts recall test load. No unresolved issue identified.
test/​standalone/​Garnet.test.vectorset/​RespVectorSetTests.cs Adds continuation, VLINKS, and VRANDMEMBER tests.
Nit (1 vote): Use nameof(VLINKSContinueSearchAsync) for the continuation test key.
test/​standalone/​Garnet.test.vectorset/​ConcurrentVaddDiskSpillTests.cs Expands quantizer coverage.
Moderate (1 vote): Reset the reused done counter between test cases to avoid masking failures.
test/​standalone/​Garnet.test.extensions/​DiskANN/​DiskANNServiceTests.cs Updates FFI integration tests. No unresolved issue identified.
libs/​server/​Storage/​Session/​MainStore/​VectorStoreOps.cs Adds neighbor and random-member operations.
Moderate (4 votes): A valid element with zero neighbors is incorrectly returned as NOTFOUND.
Moderate (2 votes): Handle int.MinValue before applying Math.Abs to VRANDMEMBER count.
libs/​server/​Storage/​Functions/​VectorStore/​VectorSessionFunctions.cs Updates vector callback handling.
Critical (3 votes): Overflow-backed values must remain pinned while native/filter callbacks use their pointers.
Critical (1 vote): Restore guaranteed four-byte alignment for callback-backed RMW records.
Critical (1 vote): Copy only WriteDesiredSize bytes into the resized callback destination.
libs/​server/​Resp/​Vector/​VectorManager.Quantization.cs Handles quantization backfill failures and shutdown. No unresolved issue identified.
libs/​server/​Resp/​Vector/​VectorManager.Migration.cs Updates migrated index recreation callbacks. No unresolved issue identified.
libs/​server/​Resp/​Vector/​VectorManager.Locking.cs Updates index creation callbacks. No unresolved issue identified.
libs/​server/​Resp/​Vector/​VectorManager.Filter.cs Changes filtering to receive attribute data directly. No unresolved issue identified.
libs/​server/​Resp/​Vector/​VectorManager.cs Adds continuation, neighbor, and random-member logic.
Critical (1 vote): Directly assigning Memory leaves a stale stack-backed SpanByte, risking writes beyond the stack allocation.
Moderate (4 votes): Dispose each previous continuation ID buffer before replacing it.
Moderate (4 votes): Free the previous pinned GCHandle on every duplicate-sampling retry.
Critical (3 votes): Read ID length prefixes as 32-bit values, not 16-bit values.
Moderate (3 votes): Dispose the old pooled owner when growing the result buffer.
Moderate (1 vote): Recompute the retry write cursor instead of double-advancing remainingIds.
Critical (1 vote): Fill the removed suffix after duplicate compaction rather than overwriting valid copied IDs.
libs/​server/​Resp/​Vector/​VectorManager.Callbacks.cs Updates DiskANN callback plumbing.
Moderate (4 votes): Pass the computed value length including record overhead to InitialIORecordSize.
libs/​server/​Resp/​Vector/​RespServerSessionVectors.cs Adds VLINKS and VRANDMEMBER responses.
Critical (4 votes): The WITHSCORES response emits an invalid aggregate; emit one two-item member/score array.
Nit (1 vote): Update and regenerate VLINKS command metadata.
Nit (1 vote): Update and regenerate VRANDMEMBER command metadata.
Critical (2 votes): RESP2 no-score results incorrectly wrap each ID in a nested array.
Critical (1 vote): Size the random_members output buffer for the requested count, prefixes, and variable-length IDs.
libs/​server/​Resp/​Vector/​DiskANNService.cs Updates native DiskANN wrappers and ABI declarations. No unresolved issue identified.
libs/​server/​InputHeader.cs Removes obsolete alignment state. No unresolved issue identified.
libs/​server/​API/​IGarnetApi.cs Updates vector API contracts. No unresolved issue identified.
libs/​server/​API/​GarnetWatchApi.cs Updates watched API forwarding. No unresolved issue identified.
libs/​server/​API/​GarnetApi.cs Updates standard API forwarding. No unresolved issue identified.
libs/​cluster/​Server/​Migration/​MigrateOperation.cs Removes obsolete migration alignment setup. No unresolved issue identified.
Directory.Packages.props Updates diskann-garnet to 5.0.3. No unresolved issue identified.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread libs/server/Resp/Vector/RespServerSessionVectors.cs
Comment thread libs/server/Resp/Vector/RespServerSessionVectors.cs
Comment thread libs/server/Resp/Vector/RespServerSessionVectors.cs
Comment thread libs/server/Resp/Vector/VectorManager.cs Outdated
Comment thread libs/server/Resp/Vector/VectorManager.cs
Comment thread libs/server/Resp/Vector/VectorManager.cs
Comment thread libs/server/Resp/Vector/VectorManager.cs
Comment thread libs/server/Storage/Session/MainStore/VectorStoreOps.cs Outdated
Comment thread libs/server/Storage/Session/MainStore/VectorStoreOps.cs
Comment thread website/docs/commands/vector-sets.md
@kevin-montrose
kevin-montrose merged commit 080b05d into main Sep 25, 2026
169 checks passed
@kevin-montrose
kevin-montrose deleted the users/kmontrose/diskANNFFIUpdates branch September 25, 2026 14:29
x@01 (x-at-01) added a commit to webc-fork/garnet that referenced this pull request Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants