Move to the hgg crate

This commit is contained in:
Kerollmops
2023-06-13 15:19:01 +02:00
committed by Clément Renault
parent 642b0f3a1b
commit 268a9ef416
9 changed files with 73 additions and 99 deletions

View File

@ -28,7 +28,6 @@ use db_cache::DatabaseCache;
use exact_attribute::ExactAttribute;
use graph_based_ranking_rule::{Exactness, Fid, Position, Proximity, Typo};
use heed::RoTxn;
use hnsw::Searcher;
use interner::{DedupInterner, Interner};
pub use logger::visual::VisualSearchLogger;
pub use logger::{DefaultSearchLogger, SearchLogger};
@ -40,7 +39,7 @@ use ranking_rules::{
use resolve_query_graph::{compute_query_graph_docids, PhraseDocIdsCache};
use roaring::RoaringBitmap;
use sort::Sort;
use space::Neighbor;
use space::{KnnMap, Neighbor};
use self::geo_sort::GeoSort;
pub use self::geo_sort::Strategy as GeoSortStrategy;
@ -48,9 +47,7 @@ use self::graph_based_ranking_rule::Words;
use self::interner::Interned;
use crate::score_details::{ScoreDetails, ScoringStrategy};
use crate::search::new::distinct::apply_distinct_rule;
use crate::{
AscDesc, DocumentId, Filter, Index, Member, Result, TermsMatchingStrategy, UserError, BEU32,
};
use crate::{AscDesc, DocumentId, Filter, Index, Member, Result, TermsMatchingStrategy, UserError};
/// A structure used throughout the execution of a search query.
pub struct SearchContext<'ctx> {
@ -450,26 +447,15 @@ pub fn execute_search(
let docids = match vector {
Some(vector) => {
// return the nearest documents that are also part of the candidates.
let mut searcher = Searcher::new();
let hnsw = ctx.index.vector_hnsw(ctx.txn)?.unwrap_or_default();
let ef = hnsw.len().min(100);
let mut dest = vec![Neighbor { index: 0, distance: 0 }; ef];
let neighbors = hnsw.nearest(&vector, ef, &mut searcher, &mut dest[..]);
let mut docids = Vec::new();
for Neighbor { index, distance } in neighbors.iter() {
let index = BEU32::new(*index as u32);
let docid = ctx.index.vector_id_docid.get(ctx.txn, &index)?.unwrap().get();
dbg!(distance, f32::from_bits(*distance));
if universe.contains(docid) {
docids.push(docid);
if docids.len() == length {
break;
}
}
}
docids
let hgg = ctx.index.vector_hgg(ctx.txn)?.unwrap_or_default();
hgg.knn_values(&vector, 100)
.into_iter()
.filter(|(Neighbor { distance, .. }, docid)| {
dbg!(distance, f32::from_bits(*distance));
universe.contains(**docid)
})
.map(|(_, docid)| *docid)
.collect()
}
// return the search docids if the vector field is not specified
None => docids,