Skip to content

Commit 164c638

Browse files
Thejas-bhatabhinavdangeti
authored andcommitted
MB-59575: Handling memory mapped content more responsibly (#241)
Requires: - blevesearch/faiss#17 - blevesearch/go-faiss#26 (Upgrade to blevesearch/[email protected]) --------- Co-authored-by: Abhinav Dangeti <[email protected]>
1 parent 9d26375 commit 164c638

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

faiss_vector_cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func (vc *vectorIndexCache) createAndCache(fieldID uint16, mem []byte, except *r
118118
indexSize, n := binary.Uvarint(mem[pos : pos+binary.MaxVarintLen64])
119119
pos += n
120120

121-
index, err = faiss.ReadIndexFromBuffer(mem[pos:pos+int(indexSize)], faiss.IOFlagReadOnly)
121+
index, err = faiss.ReadIndexFromBuffer(mem[pos:pos+int(indexSize)],
122+
faiss.IOFlagReadMmap|faiss.IOFlagSkipPrefetch)
122123
if err != nil {
123124
return nil, nil, nil, err
124125
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/RoaringBitmap/roaring v1.9.3
77
github.com/blevesearch/bleve_index_api v1.1.7
8-
github.com/blevesearch/go-faiss v1.0.15
8+
github.com/blevesearch/go-faiss v1.0.16
99
github.com/blevesearch/mmap-go v1.0.4
1010
github.com/blevesearch/scorch_segment_api/v2 v2.2.12
1111
github.com/blevesearch/vellum v1.0.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/bits-and-blooms/bitset v1.12.0 h1:U/q1fAF7xXRhFCrhROzIfffYnu+dlS38vCZ
44
github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
55
github.com/blevesearch/bleve_index_api v1.1.7 h1:KvvKVn/9+dKCEJHL6flDH3NCiXeKnK3P85e4EOgVjdM=
66
github.com/blevesearch/bleve_index_api v1.1.7/go.mod h1:PbcwjIcRmjhGbkS/lJCpfgVSMROV6TRubGGAODaK1W8=
7-
github.com/blevesearch/go-faiss v1.0.15 h1:aBrj6fwLuY8CkhECFbvkc4qhLTkrYI84QoEaw9z1jMI=
8-
github.com/blevesearch/go-faiss v1.0.15/go.mod h1:jrxHrbl42X/RnDPI+wBoZU8joxxuRwedrxqswQ3xfU8=
7+
github.com/blevesearch/go-faiss v1.0.16 h1:lfzXzzjO1mAf15MRiRY5yz6KVGr02CyRrr7m0z70Ih8=
8+
github.com/blevesearch/go-faiss v1.0.16/go.mod h1:jrxHrbl42X/RnDPI+wBoZU8joxxuRwedrxqswQ3xfU8=
99
github.com/blevesearch/mmap-go v1.0.4 h1:OVhDhT5B/M1HNPpYPBKIEJaD0F3Si+CrEKULGCDPWmc=
1010
github.com/blevesearch/mmap-go v1.0.4/go.mod h1:EWmEAOmdAS9z/pi/+Toxu99DnsbhG1TIxUoRmJw/pSs=
1111
github.com/blevesearch/scorch_segment_api/v2 v2.2.12 h1:LuBJ4AfKlMsyi/8xFhxIArEnrlAcI3qGTvzwCTdfKgA=

section_faiss_vector_index.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ func (v *vectorIndexOpaque) mergeAndWriteVectorIndexes(sbs []*SegmentBase,
286286
}
287287
// read the index bytes. todo: parallelize this
288288
indexBytes := segBase.mem[indexes[segI].startOffset : indexes[segI].startOffset+int(indexes[segI].indexSize)]
289-
index, err := faiss.ReadIndexFromBuffer(indexBytes, faiss.IOFlagReadOnly)
289+
index, err := faiss.ReadIndexFromBuffer(indexBytes,
290+
faiss.IOFlagReadMmap|faiss.IOFlagSkipPrefetch)
290291
if err != nil {
291292
freeReconstructedIndexes(vecIndexes)
292293
return err

0 commit comments

Comments
 (0)