|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -// -*- c++ -*- |
9 |
| - |
10 | 8 | #include <faiss/index_io.h>
|
11 | 9 |
|
12 | 10 | #include <faiss/impl/io.h>
|
@@ -390,8 +388,12 @@ static void write_ivf_header(const IndexIVF* ivf, IOWriter* f) {
|
390 | 388 | write_direct_map(&ivf->direct_map, f);
|
391 | 389 | }
|
392 | 390 |
|
393 |
| -void write_index(const Index* idx, IOWriter* f) { |
394 |
| - if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) { |
| 391 | +void write_index(const Index* idx, IOWriter* f, int io_flags) { |
| 392 | + if (idx == nullptr) { |
| 393 | + // eg. for a storage component of HNSW that is set to nullptr |
| 394 | + uint32_t h = fourcc("null"); |
| 395 | + WRITE1(h); |
| 396 | + } else if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) { |
395 | 397 | uint32_t h =
|
396 | 398 | fourcc(idxf->metric_type == METRIC_INNER_PRODUCT ? "IxFI"
|
397 | 399 | : idxf->metric_type == METRIC_L2 ? "IxF2"
|
@@ -772,7 +774,12 @@ void write_index(const Index* idx, IOWriter* f) {
|
772 | 774 | WRITE1(idx_hnsw_cagra->num_base_level_search_entrypoints);
|
773 | 775 | }
|
774 | 776 | write_HNSW(&idxhnsw->hnsw, f);
|
775 |
| - write_index(idxhnsw->storage, f); |
| 777 | + if (io_flags & IO_FLAG_SKIP_STORAGE) { |
| 778 | + uint32_t n4 = fourcc("null"); |
| 779 | + WRITE1(n4); |
| 780 | + } else { |
| 781 | + write_index(idxhnsw->storage, f); |
| 782 | + } |
776 | 783 | } else if (const IndexNSG* idxnsg = dynamic_cast<const IndexNSG*>(idx)) {
|
777 | 784 | uint32_t h = dynamic_cast<const IndexNSGFlat*>(idx) ? fourcc("INSf")
|
778 | 785 | : dynamic_cast<const IndexNSGPQ*>(idx) ? fourcc("INSp")
|
@@ -848,14 +855,14 @@ void write_index(const Index* idx, IOWriter* f) {
|
848 | 855 | }
|
849 | 856 | }
|
850 | 857 |
|
851 |
| -void write_index(const Index* idx, FILE* f) { |
| 858 | +void write_index(const Index* idx, FILE* f, int io_flags) { |
852 | 859 | FileIOWriter writer(f);
|
853 |
| - write_index(idx, &writer); |
| 860 | + write_index(idx, &writer, io_flags); |
854 | 861 | }
|
855 | 862 |
|
856 |
| -void write_index(const Index* idx, const char* fname) { |
| 863 | +void write_index(const Index* idx, const char* fname, int io_flags) { |
857 | 864 | FileIOWriter writer(fname);
|
858 |
| - write_index(idx, &writer); |
| 865 | + write_index(idx, &writer, io_flags); |
859 | 866 | }
|
860 | 867 |
|
861 | 868 | void write_VectorTransform(const VectorTransform* vt, const char* fname) {
|
|
0 commit comments