Skip to content

Conversation

@yuejiaointel
Copy link
Contributor

Add save and load functions to flat index

@yuejiaointel yuejiaointel changed the title fix: add simple save feature: save and load in flat index Aug 5, 2025
@yuejiaointel yuejiaointel marked this pull request as ready for review August 5, 2025 05:45
@ahuber21
Copy link
Contributor

ahuber21 commented Aug 5, 2025

Awesome, looks like a lot was already there, especially the assemble. Let's wait for comments from @ibhati

@yuejiaointel yuejiaointel requested a review from ibhati August 5, 2025 23:44
data_directory: Directory where the dataset will be saved.
Note: All directories should be separate to avoid accidental name collision with any
auxiliary files that are needed when saving the various components of the index.
Copy link
Member

Choose a reason for hiding this comment

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

I think we can remove this Note as there is only one directory in the Flat index unlike the Vamana index, which saves config/graph/data in multiple directories

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx, removed!

print("Flat, From Array, Float32")
flat = svs.Flat(data_f32, svs.DistanceType.L2)
self._do_test(flat, queries_f32, groundtruth, svs.DistanceType.L2, data_f32)
save_reload_and_test(flat, queries_f32, groundtruth, data_f32)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
save_reload_and_test(flat, queries_f32, groundtruth, data_f32)
self._do_test(flat, queries_f32, groundtruth, svs.DistanceType.L2, data_f32)
save_reload_and_test(flat, queries_f32, groundtruth, data_f32)

Copy link
Member

Choose a reason for hiding this comment

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

Please keep the original _do_test(...) call before doing save/load. The same comment applies to other calls below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx, fixed by have save_and_load and a remove_dir called before and after _do_test

svs::VectorDataLoader<float>(temp_dir), distance_type, index.get_num_threads()
);
}

Copy link
Member

Choose a reason for hiding this comment

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

Maybe do this in the end of this function followed by search and recall testing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx, moved to end of the function!

Copy link
Member

@ibhati ibhati left a comment

Choose a reason for hiding this comment

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

@yuejiaointel Thanks for incorporating the feedback. Now, it looks great to me!

@yuejiaointel yuejiaointel merged commit 91b0816 into main Aug 6, 2025
11 checks passed
@yuejiaointel yuejiaointel deleted the feature_flat_index_save_load branch August 6, 2025 20:01
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.

4 participants