Clippy warnings

This commit is contained in:
asonix 2023-07-04 14:08:31 -05:00
parent c0e2176555
commit f357ac487b
3 changed files with 51 additions and 48 deletions

View file

@ -6,6 +6,9 @@ pub(super) use self::db::{HypertreeRepo, SimilarityStyle};
mod db;
type SimilaritiesResult<const N: usize> =
Result<Vec<(f32, InternalVectorId, Vector<N>)>, TreeError>;
#[derive(Debug)]
pub(super) struct HypertreeMeta<const N: usize> {
maintenance: Pool<db::HypertreeRepo<N>, MaintenanceMessage<N>>,
@ -22,7 +25,7 @@ struct FindSimilaritiesCommand<const N: usize> {
threshold: Option<f32>,
limit: usize,
similarity_style: SimilarityStyle,
responder: oneshot::Sender<Result<Vec<(f32, InternalVectorId, Vector<N>)>, TreeError>>,
responder: oneshot::Sender<SimilaritiesResult<N>>,
}
struct AddToIndexCommand<const N: usize> {
@ -86,10 +89,7 @@ impl<const N: usize> HypertreeMeta<N> {
threshold: Option<f32>,
limit: usize,
similarity_style: SimilarityStyle,
) -> Result<
oneshot::Receiver<Result<Vec<(f32, InternalVectorId, Vector<N>)>, TreeError>>,
TreeError,
> {
) -> Result<oneshot::Receiver<SimilaritiesResult<N>>, TreeError> {
let (responder, rx) = oneshot::channel();
if self

View file

@ -98,7 +98,7 @@ const BUCKET_MULTIMAP: MultimapTableDefinition<'static, BucketId, InternalVector
const REBUILD_TABLE: TableDefinition<'static, &'static str, u64> =
TableDefinition::new("vectordb::rebuild_table");
const REBUILD_KEY: &'static str = "rebuild";
const REBUILD_KEY: &str = "rebuild";
const fn queue_table<const N: usize>(
) -> TableDefinition<'static, InternalVectorId, VectorBytes<'static, N>> {
@ -129,6 +129,7 @@ const fn hyperplane_byte_length(n: usize) -> usize {
(n + 1) * crate::F32_BYTE_ARRAY_SIZE
}
#[allow(clippy::too_many_arguments)]
fn do_add_to_index<'db, 'txn, const N: usize>(
ids_table: &mut Table<'db, 'txn, &'static str, u128>,
internal_vector_table: &mut Table<'db, 'txn, InternalVectorId, VectorBytes<N>>,
@ -186,8 +187,8 @@ fn do_add_to_index<'db, 'txn, const N: usize>(
Ok(())
}
fn next_multimap_id<'db, 'txn, H>(
table: &mut Table<'db, 'txn, &'static str, u128>,
fn next_multimap_id<H>(
table: &mut Table<'_, '_, &'static str, u128>,
handle: H,
) -> Result<u128, StorageError>
where
@ -286,6 +287,7 @@ fn do_build_hypertree<'db, 'txn, const N: usize>(
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn build_hyperplane<'db, 'txn, const N: usize, T>(
ids_table: &mut Table<'db, 'txn, &'static str, u128>,
vector_table: &T,
@ -407,6 +409,7 @@ fn insert_hyperplane<'db, 'txn, const N: usize>(
Ok(id)
}
#[allow(clippy::too_many_arguments)]
fn get_similar_vectors<'txn, const N: usize, T>(
hypertree_table: &ReadOnlyTable<'txn, HypertreeBytes<N>, BucketId>,
hyperplane_table: &ReadOnlyTable<'txn, HyperplaneId, HyperplaneBytes<N>>,
@ -873,8 +876,7 @@ impl<const N: usize> Hyperplane<N> {
.coefficients
.0
.iter()
.map(|f| f.to_be_bytes())
.flatten()
.flat_map(|f| f.to_be_bytes())
.chain(self.constant.to_be_bytes())
.collect();
@ -946,25 +948,29 @@ impl<const N: usize> Hypertree<N> {
let mut upper = Vec::with_capacity(bound_capacity);
for (i, (h, b)) in self.hyperplanes.iter().enumerate() {
if i == depth {
let bytes = h.to_be_bytes();
match i.cmp(&depth) {
std::cmp::Ordering::Equal => {
let bytes = h.to_be_bytes();
lower.extend_from_slice(&bytes[..]);
upper.extend_from_slice(&bytes[..]);
lower.extend_from_slice(&bytes[..]);
upper.extend_from_slice(&bytes[..]);
let (lower_bound, upper_bound) = direction.to_range_bounds();
let (lower_bound, upper_bound) = direction.to_range_bounds();
lower.push(lower_bound.to_byte());
upper.push(upper_bound.to_byte());
} else if i < depth {
let bytes = h.to_be_bytes();
lower.push(lower_bound.to_byte());
upper.push(upper_bound.to_byte());
}
std::cmp::Ordering::Less => {
let bytes = h.to_be_bytes();
lower.extend_from_slice(&bytes);
upper.extend_from_slice(&bytes);
lower.extend_from_slice(&bytes);
upper.extend_from_slice(&bytes);
lower.push(b.encode().to_byte());
} else {
break;
lower.push(b.encode().to_byte());
}
std::cmp::Ordering::Greater => {
break;
}
}
}
@ -1028,20 +1034,20 @@ impl HyperplaneId {
Self(u128::from_be_bytes(bytes))
}
fn to_be_bytes(&self) -> [u8; 16] {
fn to_be_bytes(self) -> [u8; 16] {
self.0.to_be_bytes()
}
}
impl Bounded {
const fn to_range_bounds(&self) -> (BoundedByte, BoundedByte) {
const fn to_range_bounds(self) -> (BoundedByte, BoundedByte) {
match self {
Self::Below => (BoundedByte::Below, BoundedByte::Above),
Self::Above => (BoundedByte::Above, BoundedByte::AboveBound),
}
}
const fn encode(&self) -> BoundedByte {
const fn encode(self) -> BoundedByte {
match self {
Self::Below => BoundedByte::Below,
Self::Above => BoundedByte::Above,
@ -1069,7 +1075,7 @@ impl BoundedByte {
}
}
fn to_byte(&self) -> u8 {
fn to_byte(self) -> u8 {
match self {
Self::BelowBound => 0,
Self::Below => 1,

View file

@ -285,18 +285,15 @@ impl<const N: usize> VectorMeta<N> {
let state = std::sync::Arc::new(repo);
let parallelism = std::thread::available_parallelism()
.map(|value| usize::from(value))
.map(usize::from)
.unwrap_or(1);
let reader = Pool::build(std::sync::Arc::clone(&state), reaper.clone(), reader_runner)
.with_lower_limit(2)
.with_upper_limit(16 * parallelism);
let insert_vector = Pool::build(
std::sync::Arc::clone(&state),
reaper.clone(),
insert_vectors_runner,
);
let insert_vector =
Pool::build(std::sync::Arc::clone(&state), reaper, insert_vectors_runner);
let maintenance = Thread::spawn(move |stopper| {
let mut index = 0;
@ -523,7 +520,7 @@ impl<const N: usize> VectorRepo<N> {
) -> Result<HashMap<VectorId, Vector<N>>, TreeError> {
let txn = self.database.begin_read()?;
Ok(get_vectors(&txn, vector_ids)?)
get_vectors(&txn, vector_ids)
}
fn find_similarities(
@ -682,8 +679,8 @@ fn with_stopper<Msg, Callback>(
}
}
fn insert_many_vectors<'db, const N: usize>(
transaction: &mut WriteTransaction<'db>,
fn insert_many_vectors<const N: usize>(
transaction: &mut WriteTransaction<'_>,
vectors: &[Vector<N>],
len: &std::sync::atomic::AtomicU64,
maintenance_sender: &flume::Sender<()>,
@ -711,12 +708,13 @@ fn insert_many_vectors<'db, const N: usize>(
.into_iter()
.unzip::<_, _, _, Vec<Option<InternalVectorId>>>();
let internal_vectors = internal_vectors.into_iter().filter_map(|id| id).collect();
let internal_vectors = internal_vectors.into_iter().flatten().collect();
let vectors_len = vector_table.len()?;
let previous_len = len.load(std::sync::atomic::Ordering::Acquire);
if vectors_len > 0 && vectors_len / 2 > previous_len {
if len
if vectors_len > 0
&& vectors_len / 2 > previous_len
&& len
.compare_exchange(
previous_len,
vectors_len,
@ -724,9 +722,8 @@ fn insert_many_vectors<'db, const N: usize>(
std::sync::atomic::Ordering::Relaxed,
)
.is_ok()
{
let _ = maintenance_sender.try_send(());
}
{
let _ = maintenance_sender.try_send(());
}
Ok((vectors, internal_vectors))
@ -768,8 +765,8 @@ fn do_insert_vector<'db, 'txn, const N: usize>(
Ok((vector_id, internal_vector_id))
}
fn get_vectors<'db, const N: usize>(
transaction: &ReadTransaction<'db>,
fn get_vectors<const N: usize>(
transaction: &ReadTransaction<'_>,
vector_ids: &[VectorId],
) -> Result<HashMap<VectorId, Vector<N>>, TreeError> {
let vector_insert_table = transaction.open_table(VECTOR_INSERT_TABLE)?;
@ -808,8 +805,8 @@ where
Ok(Some(vector))
}
fn next_id<'db, 'txn, H>(
table: &mut Table<'db, 'txn, &'static str, u128>,
fn next_id<H>(
table: &mut Table<'_, '_, &'static str, u128>,
handle: H,
) -> Result<u128, StorageError>
where
@ -844,7 +841,7 @@ impl<const N: usize> Vector<N> {
fn encode(&self) -> VectorBytes<'static, N> {
VectorBytes {
vector_bytes: std::borrow::Cow::Owned(
self.0.iter().map(|f| f.to_be_bytes()).flatten().collect(),
self.0.iter().flat_map(|f| f.to_be_bytes()).collect(),
),
_phantom: PhantomData,
}