mirror of
https://github.com/perstarkse/minne.git
synced 2026-07-04 12:01:48 +02:00
fix: replaced several instances if cloning, reduced allocations
This commit is contained in:
@@ -261,23 +261,24 @@ impl PipelineServices for DefaultPipelineServices {
|
||||
|
||||
// Embed all chunks of this document in one batch: a single lock acquisition and one
|
||||
// blocking hop, letting the backend batch the inference internally.
|
||||
let batch_len = chunk_candidates.len();
|
||||
let embeddings = self
|
||||
.embedding_provider
|
||||
.embed_batch(chunk_candidates.clone())
|
||||
.embed_batch(&chunk_candidates)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
AppError::InternalError(format!("FastEmbed embedding for chunks failed: {e}"))
|
||||
})?;
|
||||
|
||||
if embeddings.len() != chunk_candidates.len() {
|
||||
if embeddings.len() != batch_len {
|
||||
return Err(AppError::InternalError(format!(
|
||||
"embedding batch returned {} vectors for {} chunks",
|
||||
embeddings.len(),
|
||||
chunk_candidates.len()
|
||||
batch_len
|
||||
)));
|
||||
}
|
||||
|
||||
let mut chunks = Vec::with_capacity(chunk_candidates.len());
|
||||
let mut chunks = Vec::with_capacity(batch_len);
|
||||
for (chunk_text, embedding) in chunk_candidates.into_iter().zip(embeddings) {
|
||||
let chunk_struct = TextChunk::new(
|
||||
content.id().to_string(),
|
||||
|
||||
@@ -91,10 +91,10 @@ impl MockServices {
|
||||
similar_entities: vec![RetrievedEntity {
|
||||
entity: retrieved_entity,
|
||||
score: 0.8,
|
||||
chunks: vec![RetrievedChunk {
|
||||
chunks: std::sync::Arc::new(vec![RetrievedChunk {
|
||||
chunk: retrieved_chunk,
|
||||
score: 0.7,
|
||||
}],
|
||||
}]),
|
||||
}],
|
||||
analysis,
|
||||
chunk_embedding: vec![0.3; TEST_EMBEDDING_DIM],
|
||||
|
||||
Reference in New Issue
Block a user