Skip to content

Commit

Permalink
fix: make PR changes Pt II
Browse files Browse the repository at this point in the history
  • Loading branch information
marieaurore123 committed Oct 4, 2024
1 parent 27435e4 commit b55e86e
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 299 deletions.
4 changes: 2 additions & 2 deletions rig-lancedb/examples/vector_search_local_ann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ async fn main() -> Result<(), anyhow::Error> {
.execute()
.await?;

let vector_store = LanceDbVectorStore::new(table, model, "id", search_params).await?;

// See [LanceDB indexing](https://lancedb.github.io/lancedb/concepts/index_ivfpq/#product-quantization) for more information
table
.create_index(
Expand All @@ -86,6 +84,8 @@ async fn main() -> Result<(), anyhow::Error> {
.execute()
.await?;

let vector_store = LanceDbVectorStore::new(table, model, "id", search_params).await?;

// Query the index
let results = vector_store
.top_n::<VectorSearchResult>("My boss says I zindle too much, what does that mean?", 1)
Expand Down
9 changes: 5 additions & 4 deletions rig-lancedb/examples/vector_search_s3_ann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,22 @@ async fn main() -> Result<(), anyhow::Error> {
.execute()
.await?;

let vector_store = LanceDbVectorStore::new(table, model, "id", search_params).await?;

// See [LanceDB indexing](https://lancedb.github.io/lancedb/concepts/index_ivfpq/#product-quantization) for more information
vector_store
table
.create_index(
&["embedding"],
lancedb::index::Index::IvfPq(
IvfPqIndexBuilder::default()
// This overrides the default distance type of L2.
// Needs to be the same distance type as the one used in search params.
.distance_type(DistanceType::Cosine),
),
&["embedding"],
)
.execute()
.await?;

let vector_store = LanceDbVectorStore::new(table, model, "id", search_params).await?;

// Query the index
let results = vector_store
.top_n::<VectorSearchResult>("I'm always looking for my phone, I always seem to forget it in the most counterintuitive places. What's the word for this feeling?", 1)
Expand Down
5 changes: 3 additions & 2 deletions rig-lancedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ impl<M: EmbeddingModel + std::marker::Sync + Send> VectorStoreIndex for LanceDbV
.execute_query()
.await?
.into_iter()
.map(|value| {
.enumerate()
.map(|(i, value)| {
Ok((
match value.get("_distance") {
Some(Value::Number(distance)) => distance.as_f64().unwrap_or_default(),
_ => 0.0,
},
match value.get(self.id_field.clone()) {
Some(Value::String(id)) => id.to_string(),
_ => "".to_string(),
_ => format!("unknown{i}"),
},
serde_json::from_value(value).map_err(serde_to_rig_error)?,
))
Expand Down
Loading

0 comments on commit b55e86e

Please sign in to comment.