fix: replaced several instances if cloning, reduced allocations

This commit is contained in:
Per Stark
2026-06-06 19:45:18 +02:00
parent 93c65970f1
commit 676fdbc132
12 changed files with 254 additions and 110 deletions
+5 -4
View File
@@ -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(),
+2 -2
View File
@@ -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],