Files are often authored once and read / used many times. When authoring a file performance is less important and there is plenty of file space available. Indices are for the performance for using the file which is more important than the performance for authoring it.
If storage and concern aren't a concern when writing, then you probably shouldn't be doing workarounds to include the index in the file itself. Follow the dbm approach and separate both into two different files.
Which is what dbm, bdb, Windows search indexes, IBM datasets, and so many, many other standards will do.
Separate files isn't always the answer. It can be more awkward to need to download both and always keep them together compared to when it's a single file.
But if you're writing indices, there's a good chance that you do care about performance.