Skip to content

Commit 08059f8

Browse files
MB-59575: Handling memory mapped content more responsibly (#241)
Requires: - blevesearch/faiss#17 - blevesearch/go-faiss#26 (Upgrade to blevesearch/go-faiss@1.0.16) --------- Co-authored-by: Abhinav Dangeti <abhinav@couchbase.com>
1 parent a9fced1 commit 08059f8

4 files changed

+7
-5
lines changed

faiss_vector_cache.go

+2-1
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

+1-1
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

+2-2
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

+2-1
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)