mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-17 01:02:28 +00:00
This PR is part of the documentation revamp. Once the full set of PRs is merged, we’ll publish the combined site to staging for review before updating docs.lancedb.com. Ingestion, search and integration examples are incomplete or inconsistent across languages, and some guidance misstates SDK behavior. This brings the guides and their example sources together. It includes complete Python, TypeScript and Rust workflows, isolated provider and reranker examples, the Superlinked corrections, and guidance on retries that can duplicate writes. Stacked on #4491. Each MDX file has one PR owner. Rebase onto main after #4491 is squash-merged. Local assembly, Mint validation and link checks pass. Example code is unchanged from the previously validated package. Publication stays held through integration.
7 lines
2.5 KiB
Plaintext
7 lines
2.5 KiB
Plaintext
{/* Auto-generated by scripts/mdx_snippets_gen.py. Do not edit manually. */}
|
|
|
|
export const RsExampleBody = "use arrow_array::types::Float32Type;\nuse arrow_array::{FixedSizeListArray, Int64Array, RecordBatch, RecordBatchIterator, StringArray};\nuse arrow_schema::{DataType, Field, Schema};\nuse futures::TryStreamExt;\nuse lancedb::query::{ExecutableQuery, QueryBase, Select};\nuse std::sync::Arc;\n\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n let directory = tempfile::tempdir()?;\n let db = lancedb::connect(directory.path().to_str().unwrap())\n .execute()\n .await?;\n let schema = Arc::new(Schema::new(vec![\n Field::new(\"id\", DataType::Int64, false),\n Field::new(\"text\", DataType::Utf8, false),\n Field::new(\"category\", DataType::Utf8, false),\n Field::new(\n \"vector\",\n DataType::FixedSizeList(Arc::new(Field::new(\"item\", DataType::Float32, true)), 2),\n true,\n ),\n ]));\n let batch = RecordBatch::try_new(\n schema.clone(),\n vec![\n Arc::new(Int64Array::from(vec![1, 2, 3])),\n Arc::new(StringArray::from(vec![\n \"A puppy playing in the park\",\n \"A dog resting at home\",\n \"A guide to growing tomatoes\",\n ])),\n Arc::new(StringArray::from(vec![\"animals\", \"animals\", \"gardening\"])),\n Arc::new(\n FixedSizeListArray::from_iter_primitive::<Float32Type, _, _>(\n [[1.0, 0.0], [0.9, 0.1], [0.0, 1.0]]\n .into_iter()\n .map(|v| Some(v.into_iter().map(Some).collect::<Vec<_>>())),\n 2,\n ),\n ),\n ],\n )?;\n let reader = RecordBatchIterator::new(vec![Ok(batch)].into_iter(), schema);\n let table = db\n .create_table(\n \"documents\",\n Box::new(reader) as Box<dyn arrow_array::RecordBatchReader + Send>,\n )\n .execute()\n .await?;\n let query = table\n .vector_search(&[1.0_f32, 0.0])?\n .select(Select::columns(&[\"id\", \"text\", \"_distance\"]))\n .limit(2);\n println!(\"Plan: {}\", query.explain_plan(false).await?);\n println!(\"Measured execution: {}\", query.analyze_plan().await?);\n let rows: Vec<RecordBatch> = query.execute().await?.try_collect().await?;\n println!(\"{rows:?}\");\n";
|
|
|
|
export const RsExampleTail = " Ok(())\n}\n";
|
|
|