Skip to content

Commit

Permalink
fix(embed): panic if number of embeddings and node are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jun 26, 2024
1 parent 926cc0c commit 3143308
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions swiftide/src/transformers/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
};
use anyhow::Result;

Check warning on line 7 in swiftide/src/transformers/embed.rs

View workflow job for this annotation

GitHub Actions / Lint & Test

unused import: `anyhow::Result`

Check warning on line 7 in swiftide/src/transformers/embed.rs

View workflow job for this annotation

GitHub Actions / Lint & Test

unused import: `anyhow::Result`
use async_trait::async_trait;
use itertools::Itertools as _;

/// A transformer that can generate embeddings for an `IngestionNode`
///
Expand Down Expand Up @@ -72,14 +73,14 @@ impl BatchableTransformer for Embed {
.map(|embeddings| {
nodes
.into_iter()
.zip(embeddings)
// Will panic if the number of embeddings doesn't match the number of nodes
.zip_eq(embeddings)
.map(|(mut n, v)| {
n.vector = Some(v);
Ok(n)
n
})
.collect::<Vec<Result<IngestionNode>>>()
.collect::<Vec<_>>()
})
.unwrap_or_else(|e| vec![Err(e)])
.into()
}

Expand Down

0 comments on commit 3143308

Please sign in to comment.