-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ENH]: More precise calculation of hnsw cache item weight #4657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ENH]: More precise calculation of hnsw cache item weight #4657
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
This PR updates the weight estimation logic for HnswIndexRef cache items to more accurately account for the memory footprint, incorporating not just the L0 embeddings but also graph nodes, edges, and higher HNSW levels. The approach introduces a constant for the M parameter (node connections) and doubles the size calculation to approximate additional HNSW layers. This summary was automatically generated by @propel-code-bot |
WalkthroughThis update refines the memory usage estimation logic in the Changes
Sequence DiagramThis diagram shows the interactions between components: sequenceDiagram
title HnswIndexRef Weight Calculation Flow
participant Client
participant HnswIndexRef
participant IndexInner
Client->>HnswIndexRef: weight()
activate HnswIndexRef
HnswIndexRef->>IndexInner: read()
activate IndexInner
IndexInner-->>HnswIndexRef: index (RwLockReadGuard)
deactivate IndexInner
Note over HnswIndexRef: Check if index is empty
HnswIndexRef->>IndexInner: len_with_deleted()
activate IndexInner
IndexInner-->>HnswIndexRef: count (including deleted items)
deactivate IndexInner
alt index is empty (len_with_deleted() == 0)
HnswIndexRef-->>Client: return 1
else index has elements
HnswIndexRef->>IndexInner: len_with_deleted()
activate IndexInner
IndexInner-->>HnswIndexRef: count (including deleted items)
deactivate IndexInner
HnswIndexRef->>IndexInner: dimensionality()
activate IndexInner
IndexInner-->>HnswIndexRef: dimensions
deactivate IndexInner
Note over HnswIndexRef: Calculate memory usage
Note over HnswIndexRef: 1. Graph bytes = M * sizeof(u32) * len_with_deleted()
Note over HnswIndexRef: 2. Embedding bytes = len_with_deleted() * sizeof(f32) * dimensionality
Note over HnswIndexRef: 3. Total bytes = 2 * (graph_bytes + embedding_bytes)
Note over HnswIndexRef: 4. Convert to MB
alt as_mb == 0
HnswIndexRef-->>Client: return 1
else as_mb > 0
HnswIndexRef-->>Client: return as_mb
end
end
deactivate HnswIndexRef
Note for Windsurf Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts belowEmoji Descriptions:
Interact with the Bot:
Also you can trigger various commands with the bot by doing The current supported commands are
More commands to be added soon. |
Description of changes
Summarize the changes made by this PR.
Test plan
How are these changes tested?
pytest
for python,yarn test
for js,cargo test
for rustDocumentation Changes
None