|
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"
|
@@ -765,7 +767,12 @@ void write_index(const Index* idx, IOWriter* f) {
|
765 | 767 | WRITE1(h);
|
766 | 768 | write_index_header(idxhnsw, f);
|
767 | 769 | write_HNSW(&idxhnsw->hnsw, f);
|
768 |
| - write_index(idxhnsw->storage, f); |
| 770 | + if (io_flags & IO_FLAG_SKIP_STORAGE) { |
| 771 | + uint32_t n4 = fourcc("null"); |
| 772 | + WRITE1(n4); |
| 773 | + } else { |
| 774 | + write_index(idxhnsw->storage, f); |
| 775 | + } |
769 | 776 | } else if (const IndexNSG* idxnsg = dynamic_cast<const IndexNSG*>(idx)) {
|
770 | 777 | uint32_t h = dynamic_cast<const IndexNSGFlat*>(idx) ? fourcc("INSf")
|
771 | 778 | : dynamic_cast<const IndexNSGPQ*>(idx) ? fourcc("INSp")
|
@@ -841,14 +848,14 @@ void write_index(const Index* idx, IOWriter* f) {
|
841 | 848 | }
|
842 | 849 | }
|
843 | 850 |
|
844 |
| -void write_index(const Index* idx, FILE* f) { |
| 851 | +void write_index(const Index* idx, FILE* f, int io_flags) { |
845 | 852 | FileIOWriter writer(f);
|
846 |
| - write_index(idx, &writer); |
| 853 | + write_index(idx, &writer, io_flags); |
847 | 854 | }
|
848 | 855 |
|
849 |
| -void write_index(const Index* idx, const char* fname) { |
| 856 | +void write_index(const Index* idx, const char* fname, int io_flags) { |
850 | 857 | FileIOWriter writer(fname);
|
851 |
| - write_index(idx, &writer); |
| 858 | + write_index(idx, &writer, io_flags); |
852 | 859 | }
|
853 | 860 |
|
854 | 861 | void write_VectorTransform(const VectorTransform* vt, const char* fname) {
|
|
0 commit comments