-
Notifications
You must be signed in to change notification settings - Fork 10
[ENH]: Added functionality to use an in-memory intermediary to load #35
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
Conversation
da6fa1c to
736bfd1
Compare
77bc087 to
06f82f7
Compare
src/hnsw.rs
Outdated
| #[repr(C)] | ||
| pub struct HnswDataViewFFI { | ||
| _data: [u8; 0], | ||
| _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally mut?
src/hnsw.rs
Outdated
| // Create HnswData FFI structure and set the buffers | ||
| let ffi_ptr = unsafe { create_hnsw_data_view(header_buffer.as_ptr(), header_buffer.len(), data_level0_buffer.as_ptr(), data_level0_buffer.len(), length_buffer.as_ptr(), length_buffer.len(), link_list_buffer.as_ptr(), link_list_buffer.len()) }; | ||
| if ffi_ptr.is_null() { | ||
| return Err(HnswError::FFIException("Failed to create HnswData FFI structure".to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've generally isolated the FFI exception to exceptions thrown in C++, that makes it clear to debug where the error is. Could we make this a custom error?
src/hnsw.rs
Outdated
|
|
||
| // Opaque struct for memory buffers | ||
| #[repr(C)] | ||
| pub struct HnswDataFFI { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming nit - DataFFI vs HnswDataFFI, I know its HNSW
src/bindings.cpp
Outdated
| // Memory buffer management functions | ||
| hnswlib::HnswDataMut* create_mutable_hnsw_data(char* header_buffer, size_t header_size, char* data_level0_buffer, size_t data_level0_size, char* length_buffer, size_t length_size, char* link_list_buffer, size_t link_list_size) | ||
| { | ||
| return new hnswlib::HnswDataMut(header_buffer, header_size, data_level0_buffer, data_level0_size, length_buffer, length_size, link_list_buffer, link_list_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we error handle here just defensively?
src/bindings.cpp
Outdated
|
|
||
| const hnswlib::HnswDataView* hnsw_data_to_view(hnswlib::HnswDataMut* hnsw_data) | ||
| { | ||
| return hnsw_data->getView(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we error handle here just defensively?
src/bindings.cpp
Outdated
|
|
||
| hnswlib::HnswDataView* create_hnsw_data_view(char* header_buffer, size_t header_size, char* data_level0_buffer, size_t data_level0_size, char* length_buffer, size_t length_size, char* link_list_buffer, size_t link_list_size) | ||
| { | ||
| return new hnswlib::HnswDataView(header_buffer, header_size, data_level0_buffer, data_level0_size, length_buffer, length_size, link_list_buffer, link_list_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we error handle here just defensively?
HammadB
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Some of the size calcs seem descrepant (void * vs unsigned int)
- Reallocs need to happen the same way as the malloc changes
- The link list malloc is probably not OK we should alloc all memory on one side of the FFI boundary, ideally rust
06f82f7 to
586ac7f
Compare
| mutable std::atomic<size_t> cur_element_count{0}; // current number of elements | ||
| size_t size_data_per_element_{0}; | ||
| size_t size_links_per_element_{0}; | ||
| unsigned int size_links_per_element_{0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been serializing and reading this as unsigned int so just making it consistent here.
src/hnsw.rs
Outdated
| pub dimensionality: i32, | ||
| pub persist_path: PathBuf, | ||
| pub ef_search: usize, | ||
| pub hnsw_data: HnswData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be in the config, its not really config
586ac7f to
834a0ee
Compare

No description provided.