mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
Add support functions for accessing arroy writers and readers
This commit is contained in:
parent
e172e938e7
commit
d35278320e
@ -1595,6 +1595,22 @@ impl Index {
|
|||||||
.unwrap_or_default())
|
.unwrap_or_default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn arroy_readers<'a>(
|
||||||
|
&'a self,
|
||||||
|
rtxn: &'a RoTxn<'a>,
|
||||||
|
embedder_id: u8,
|
||||||
|
) -> impl Iterator<Item = Result<arroy::Reader<arroy::distances::Angular>>> + 'a {
|
||||||
|
crate::vector::arroy_db_range_for_embedder(embedder_id).map_while(move |k| {
|
||||||
|
arroy::Reader::open(rtxn, k, self.vector_arroy)
|
||||||
|
.map(Some)
|
||||||
|
.or_else(|e| match e {
|
||||||
|
arroy::Error::MissingMetadata => Ok(None),
|
||||||
|
e => Err(e.into()),
|
||||||
|
})
|
||||||
|
.transpose()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn put_search_cutoff(&self, wtxn: &mut RwTxn<'_>, cutoff: u64) -> heed::Result<()> {
|
pub(crate) fn put_search_cutoff(&self, wtxn: &mut RwTxn<'_>, cutoff: u64) -> heed::Result<()> {
|
||||||
self.main.remap_types::<Str, BEU64>().put(wtxn, main_key::SEARCH_CUTOFF, &cutoff)
|
self.main.remap_types::<Str, BEU64>().put(wtxn, main_key::SEARCH_CUTOFF, &cutoff)
|
||||||
}
|
}
|
||||||
|
@ -49,19 +49,8 @@ impl<Q: RankingRuleQueryTrait> VectorSort<Q> {
|
|||||||
ctx: &mut SearchContext<'_>,
|
ctx: &mut SearchContext<'_>,
|
||||||
vector_candidates: &RoaringBitmap,
|
vector_candidates: &RoaringBitmap,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let writer_index = (self.embedder_index as u16) << 8;
|
let readers: std::result::Result<Vec<_>, _> =
|
||||||
let readers: std::result::Result<Vec<_>, _> = (0..=u8::MAX)
|
ctx.index.arroy_readers(ctx.txn, self.embedder_index).collect();
|
||||||
.map_while(|k| {
|
|
||||||
arroy::Reader::open(ctx.txn, writer_index | (k as u16), ctx.index.vector_arroy)
|
|
||||||
.map(Some)
|
|
||||||
.or_else(|e| match e {
|
|
||||||
arroy::Error::MissingMetadata => Ok(None),
|
|
||||||
e => Err(e),
|
|
||||||
})
|
|
||||||
.transpose()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let readers = readers?;
|
let readers = readers?;
|
||||||
|
|
||||||
let target = &self.target;
|
let target = &self.target;
|
||||||
|
@ -561,10 +561,8 @@ where
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
pool.install(|| {
|
pool.install(|| {
|
||||||
let writer_index = (embedder_index as u16) << 8;
|
for k in crate::vector::arroy_db_range_for_embedder(embedder_index) {
|
||||||
for k in 0..=u8::MAX {
|
let writer = arroy::Writer::new(vector_arroy, k, dimension);
|
||||||
let writer =
|
|
||||||
arroy::Writer::new(vector_arroy, writer_index | (k as u16), dimension);
|
|
||||||
if writer.is_empty(wtxn)? {
|
if writer.is_empty(wtxn)? {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -634,16 +634,9 @@ pub(crate) fn write_typed_chunk_into_index(
|
|||||||
let embedder_index = index.embedder_category_id.get(wtxn, &embedder_name)?.ok_or(
|
let embedder_index = index.embedder_category_id.get(wtxn, &embedder_name)?.ok_or(
|
||||||
InternalError::DatabaseMissingEntry { db_name: "embedder_category_id", key: None },
|
InternalError::DatabaseMissingEntry { db_name: "embedder_category_id", key: None },
|
||||||
)?;
|
)?;
|
||||||
let writer_index = (embedder_index as u16) << 8;
|
|
||||||
// FIXME: allow customizing distance
|
// FIXME: allow customizing distance
|
||||||
let writers: Vec<_> = (0..=u8::MAX)
|
let writers: Vec<_> = crate::vector::arroy_db_range_for_embedder(embedder_index)
|
||||||
.map(|k| {
|
.map(|k| arroy::Writer::new(index.vector_arroy, k, expected_dimension))
|
||||||
arroy::Writer::new(
|
|
||||||
index.vector_arroy,
|
|
||||||
writer_index | (k as u16),
|
|
||||||
expected_dimension,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// remove vectors for docids we want them removed
|
// remove vectors for docids we want them removed
|
||||||
|
@ -442,3 +442,9 @@ impl DistributionShift {
|
|||||||
pub const fn is_cuda_enabled() -> bool {
|
pub const fn is_cuda_enabled() -> bool {
|
||||||
cfg!(feature = "cuda")
|
cfg!(feature = "cuda")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn arroy_db_range_for_embedder(embedder_id: u8) -> impl Iterator<Item = u16> {
|
||||||
|
let embedder_id = (embedder_id as u16) << 8;
|
||||||
|
|
||||||
|
(0..=u8::MAX).map(move |k| embedder_id | (k as u16))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user