|
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,7 +388,7 @@ 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) { |
| 391 | +void write_index(const Index* idx, IOWriter* f, int io_flags) { |
394 | 392 | if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) {
|
395 | 393 | uint32_t h =
|
396 | 394 | fourcc(idxf->metric_type == METRIC_INNER_PRODUCT ? "IxFI"
|
@@ -765,6 +763,12 @@ void write_index(const Index* idx, IOWriter* f) {
|
765 | 763 | WRITE1(h);
|
766 | 764 | write_index_header(idxhnsw, f);
|
767 | 765 | write_HNSW(&idxhnsw->hnsw, f);
|
| 766 | + if (io_flags & IO_FLAG_SKIP_STORAGE) { |
| 767 | + uint32_t n4 = fourcc("null"); |
| 768 | + WRITE1(n4); |
| 769 | + } else { |
| 770 | + write_index(idxhnsw->storage, f); |
| 771 | + } |
768 | 772 | write_index(idxhnsw->storage, f);
|
769 | 773 | } else if (const IndexNSG* idxnsg = dynamic_cast<const IndexNSG*>(idx)) {
|
770 | 774 | uint32_t h = dynamic_cast<const IndexNSGFlat*>(idx) ? fourcc("INSf")
|
@@ -841,14 +845,14 @@ void write_index(const Index* idx, IOWriter* f) {
|
841 | 845 | }
|
842 | 846 | }
|
843 | 847 |
|
844 |
| -void write_index(const Index* idx, FILE* f) { |
| 848 | +void write_index(const Index* idx, FILE* f, int io_flags) { |
845 | 849 | FileIOWriter writer(f);
|
846 |
| - write_index(idx, &writer); |
| 850 | + write_index(idx, &writer, io_flags); |
847 | 851 | }
|
848 | 852 |
|
849 |
| -void write_index(const Index* idx, const char* fname) { |
| 853 | +void write_index(const Index* idx, const char* fname, int io_flags) { |
850 | 854 | FileIOWriter writer(fname);
|
851 |
| - write_index(idx, &writer); |
| 855 | + write_index(idx, &writer, io_flags); |
852 | 856 | }
|
853 | 857 |
|
854 | 858 | void write_VectorTransform(const VectorTransform* vt, const char* fname) {
|
|
0 commit comments