Files
lancedb/docs/web/snippets/basic_usage.mdx
Jack YeandBrendan Clement 47b7babc08 docs: bring the open-source documentation into this repository (#4122)
Move the public website pages into `docs/web` beside the SDK, with
shared navigation and executable example sources in `docs/web-tests`.
The combined website is assembled by
[lancedb/docs#355](https://github.com/lancedb/docs/pull/355), with six
Enterprise replacements from
[lancedb/sophon#7681](https://github.com/lancedb/sophon/pull/7681).

This includes Function guidance, runnable Quickstarts, regenerated
snippets, production contact/demo fixes, the legacy SQL route, and the
LeRobot redirect. LeRobot remains attributed to Geneva; all 34 Geneva
pages remain in the docs repository until Function officially launches.

Materialized-view guidance follows the full rebuild refresh introduced
by #4373: local refresh writes the complete result, has no `full`
argument, supports `source_version`, and no longer requires stable row
IDs. Deployment SQL refresh options and stable-ID setup are qualified by
version/configuration. Function input guidance distinguishes ordinary
stored columns from computed inputs supported by newer deployments.

**Validation:** independently accepted local checks include 95 Python
tests (real Enterprise excluded), eight TypeScript tests, Rust
Quickstart, snippet parity, typos, deterministic assembly, Mint
validation and links/anchors/redirects. The combined baseline retains
all 181 production routes and 17 legacy redirects. Examples ran locally
against source-built Python SDK 0.40.0b13; existing GitHub workflows do
not run `docs/web-tests`. New main at `069b2f7d` is 0.41.0b0 and adds
computed Function inputs; that SDK was not exercised by the accepted
tests. Latest prose corrections receive focused site validation.

**Merge/rollout:** merge this and #7681 before #355's combined CI, which
reads producer `main`. This is migration infrastructure: section
overlays, source-owned skills and automatic versioned paired releases
remain follow-ups. The current manual publisher is transitional. Hosted
validation, a supported SDK/Enterprise release pair and a real
Enterprise walkthrough remain pending.

Production Mintlify watches `lancedb/docs:deploy-freeze`, directory
`docs`; preserve that source through review. The separate SDK GitHub
Pages reference workflow rebuilds on main merges.

**Updated-head CI (9a50f8db):**
[Typos](https://github.com/lancedb/lancedb/actions/runs/37654185443/job/112904990558),
[PR
title](https://github.com/lancedb/lancedb/actions/runs/37654179507/job/112904974595)
and
[Aikido](https://app.aikido.dev/featurebranch/scan/215386145?groupId=74229)
pass. Critical findings in the example lockfiles were patched: all Sharp
copies use 0.35.5, protobufjs 7.6.6, tar 7.5.22, quinn-proto 0.11.19,
zerovec 0.11.8 and zerovec-derive 0.11.6. The SDK's product dependencies
are unchanged. The revised lockfiles pass eight TypeScript examples,
HuggingFace decode/resize/crop/rescale/normalize plus AVIF roundtrip,
and Rust Quickstart. Aikido passing does not mean every advisory is
cleared; npm still reports 29 high and five moderate advisories in the
example dependency graph. No scanner bypass or suppression was added.

The Function prose correction passes combined/standalone Mint,
deterministic assembly, routes and assets. The revised 325-file site
checksum is
`175bec06864abb400dd292e667ba93448c0479b8359fd7bf6146afabf9040647`. This
PR remains open for independent review; further merges are on hold.

---------

Co-authored-by: Brendan Clement <brendan.clement@lancedb.com>
2026-10-07 11:15:00 -07:00

101 lines
14 KiB
Plaintext

{/* Auto-generated by scripts/mdx_snippets_gen.py. Do not edit manually. */}
export const PyBasicAddColumns = "table.add_columns(\n {\n \"power\": \"cast(((stats.strength + stats.courage + stats.magic + stats.wisdom) / 4.0) as float)\"\n }\n)\n";
export const PyBasicAddData = "magical_characters = [\n {\n \"id\": 9,\n \"name\": \"Morgan le Fay\",\n \"role\": \"Sorceress\",\n \"description\": \"A powerful enchantress, Arthur's half-sister, and a complex figure who oscillates between aiding and opposing Camelot.\",\n \"vector\": [0.10, 0.84, 0.25, 0.70],\n \"stats\": { \"strength\": 2, \"courage\": 3, \"magic\": 5, \"wisdom\": 4 }\n },\n {\n \"id\": 10,\n \"name\": \"The Lady of the Lake\",\n \"role\": \"Mystical Guardian\",\n \"description\": \"A mysterious supernatural figure associated with Avalon, known for giving Arthur the sword Excalibur.\",\n \"vector\": [0.00, 0.90, 0.58, 0.88],\n \"stats\": { \"strength\": 2, \"courage\": 3, \"magic\": 5, \"wisdom\": 5 }\n }\n]\ntable.add(magical_characters)\n";
export const PyBasicAsyncApi = "import lancedb\n\nasync_db = await lancedb.connect_async(uri)\nasync_table = await async_db.create_table(\n \"camelot_async\",\n data=data,\n mode=\"overwrite\",\n)\n\nquery_vector = [0.03, 0.85, 0.61, 0.90]\nasync_results = await (\n await async_table.search(query_vector)\n).limit(5).select([\"name\", \"role\", \"description\"]).to_polars()\nprint(async_results)\n";
export const PyBasicCreateEmptyTable = "schema = pa.schema(\n [\n pa.field(\"id\", pa.uint16()),\n pa.field(\"name\", pa.string()),\n pa.field(\"role\", pa.string()),\n pa.field(\"description\", pa.string()),\n pa.field(\"vector\", pa.list_(pa.float32(), 4)),\n pa.field(\n \"stats\",\n pa.struct(\n [\n pa.field(\"strength\", pa.int8()),\n pa.field(\"courage\", pa.int8()),\n pa.field(\"magic\", pa.int8()),\n pa.field(\"wisdom\", pa.int8()),\n ]\n ),\n ),\n ]\n)\ndb.create_table(\"camelot_pa\", schema=schema, mode=\"overwrite\")\n";
export const PyBasicCreateTable = "table = db.create_table(\"camelot\", data=data, mode=\"overwrite\")\n";
export const PyBasicCreateTablePandas = "pandas_df = pd.DataFrame(data)\ntable_pd = db.create_table(\"camelot_pd\", data=pandas_df, mode=\"overwrite\")\n";
export const PyBasicCreateTablePolars = "polars_df = pl.DataFrame(data)\ntable_pl = db.create_table(\"camelot_pl\", data=polars_df, mode=\"overwrite\")\n";
export const PyBasicDeleteRows = "table.delete('role = \"Traitor Knight\"')\n";
export const PyBasicDropColumns = "table.drop_columns([\"power\"])\n";
export const PyBasicDropTable = "db.drop_table(\"camelot\")\n";
export const PyBasicImports = "import json\n\nimport lancedb\nimport pandas as pd\nimport polars as pl\nimport pyarrow as pa\n";
export const PyBasicOpenTable = "table = db.open_table(\"camelot\")\n";
export const PyBasicSortPolars = "# Sort Polars DataFrame by power in descending order\nprint(r4.sort(\"power\", descending=True).limit(5))\n";
export const PyBasicVectorSearch = "query_vector = [0.03, 0.85, 0.61, 0.90]\nresult = table.search(query_vector).limit(5).to_polars()\nprint(result)\n";
export const PyBasicVectorSearchQ1 = "# Who are the characters similar to \"wizard\"?\nquery_vector_1 = [0.03, 0.85, 0.61, 0.90]\nr1 = (\n table.search(query_vector_1)\n .limit(5)\n .select([\"name\", \"role\", \"description\"])\n .to_polars()\n)\nprint(r1)\n";
export const PyBasicVectorSearchQ2 = "# Who are the characters with high magic stats?\nquery_vector_2 = [0.03, 0.85, 0.61, 0.90]\nr2 = (\n table.search(query_vector_2)\n .where(\"stats.magic > 3\")\n .select([\"name\", \"role\", \"description\"])\n .limit(5)\n .to_polars()\n)\nprint(r2)\n";
export const PyBasicVectorSearchQ3 = "# Who are the strongest characters?\nr3 = (\n table.search()\n .where(\"stats.strength > 3\")\n .select([\"name\", \"role\", \"description\"])\n .limit(5)\n .to_polars()\n)\nprint(r3)\n";
export const PyBasicVectorSearchQ4 = "# Who are the strongest characters?\nr4 = (\n table.search()\n .select([\"name\", \"role\", \"description\", \"power\"])\n .to_polars()\n)\nprint(r4)\n";
export const PyDataLoad = "with open(data_path, \"r\") as f:\n data = json.load(f)\n";
export const TsBasicAddColumns = "await table.addColumns([\n {\n name: \"power\",\n valueSql:\n \"cast(((stats.strength + stats.courage + stats.magic + stats.wisdom) / 4.0) as float)\",\n },\n]);\n";
export const TsBasicAddData = "const magicalCharacters = [\n {\n id: 9,\n name: \"Morgan le Fay\",\n role: \"Sorceress\",\n description:\n \"A powerful enchantress, Arthur's half-sister, and a complex figure who oscillates between aiding and opposing Camelot.\",\n vector: [0.1, 0.84, 0.25, 0.7],\n stats: { strength: 2, courage: 3, magic: 5, wisdom: 4 },\n },\n {\n id: 10,\n name: \"The Lady of the Lake\",\n role: \"Mystical Guardian\",\n description:\n \"A mysterious supernatural figure associated with Avalon, known for giving Arthur the sword Excalibur.\",\n vector: [0.0, 0.9, 0.58, 0.88],\n stats: { strength: 2, courage: 3, magic: 5, wisdom: 5 },\n },\n];\nawait table.add(magicalCharacters);\n";
export const TsBasicCreateEmptyTable = "const schema = new arrow.Schema([\n new arrow.Field(\"id\", new arrow.Int16()),\n new arrow.Field(\"name\", new arrow.Utf8()),\n new arrow.Field(\"role\", new arrow.Utf8()),\n new arrow.Field(\"description\", new arrow.Utf8()),\n new arrow.Field(\n \"vector\",\n new arrow.FixedSizeList(\n 4,\n new arrow.Field(\"item\", new arrow.Float32(), true),\n ),\n ),\n new arrow.Field(\n \"stats\",\n new arrow.Struct([\n new arrow.Field(\"strength\", new arrow.Int8()),\n new arrow.Field(\"courage\", new arrow.Int8()),\n new arrow.Field(\"magic\", new arrow.Int8()),\n new arrow.Field(\"wisdom\", new arrow.Int8()),\n ]),\n ),\n]);\nawait db.createEmptyTable(\"camelot_empty\", schema, { mode: \"overwrite\" });\n";
export const TsBasicCreateTable = "let table = await db.createTable(\"camelot\", data, {\n mode: \"overwrite\",\n});\n";
export const TsBasicDeleteRows = "await table.delete('role = \"Traitor Knight\"');\n";
export const TsBasicDropColumns = "await table.dropColumns([\"power\"]);\n";
export const TsBasicDropTable = "await db.dropTable(\"camelot\");\n";
export const TsBasicImports = "import * as lancedb from \"@lancedb/lancedb\";\nimport * as arrow from \"apache-arrow\";\n";
export const TsBasicOpenTable = "table = await db.openTable(\"camelot\");\n";
export const TsBasicVectorSearch = "const queryVector = [0.03, 0.85, 0.61, 0.9];\nconst result = await table.search(queryVector).limit(5).toArray();\nconsole.log(result);\n";
export const TsBasicVectorSearchQ1 = "// Who are the characters similar to \"wizard\"?\nconst queryVector1 = [0.03, 0.85, 0.61, 0.9];\nconst r1 = await table\n .search(queryVector1)\n .limit(5)\n .select([\"name\", \"role\", \"description\"])\n .toArray();\nconsole.log(r1);\n";
export const TsBasicVectorSearchQ2 = "// Who are the characters similar to \"wizard\" with high magic stats?\nconst queryVector2 = [0.03, 0.85, 0.61, 0.9];\nconst r2 = await table\n .search(queryVector2)\n .where(\"stats.magic > 3\")\n .select([\"name\", \"role\", \"description\"])\n .limit(5)\n .toArray();\nconsole.log(r2);\n";
export const TsBasicVectorSearchQ3 = "// Who are the strongest characters?\nconst r3 = await table\n .query()\n .where(\"stats.strength > 3\")\n .select([\"name\", \"role\", \"description\"])\n .limit(5)\n .toArray();\nconsole.log(r3);\n";
export const TsBasicVectorSearchQ4 = "// Who are the strongest characters?\nconst r4 = await table\n .query()\n .select([\"name\", \"role\", \"description\", \"power\"])\n .toArray();\nconsole.log(r4);\n";
export const TsDataLoad = "const data = JSON.parse(fs.readFileSync(dataPath, \"utf-8\"));\n";
export const RsBasicAddColumns = "table\n .add_columns(\n NewColumnTransform::SqlExpressions(vec![(\n \"power\".to_string(),\n \"cast(((stats.strength + stats.courage + stats.magic + stats.wisdom) / 4.0) as float)\"\n .to_string(),\n )]),\n None,\n )\n .await\n .unwrap();\n";
export const RsBasicAddData = "let magical_characters = vec![\n Character {\n id: 9,\n name: \"Morgan le Fay\".to_string(),\n role: \"Sorceress\".to_string(),\n description: \"A powerful enchantress, Arthur's half-sister, and a complex figure who oscillates between aiding and opposing Camelot.\".to_string(),\n vector: [0.10, 0.84, 0.25, 0.70],\n stats: Stats {\n strength: 2,\n courage: 3,\n magic: 5,\n wisdom: 4,\n },\n },\n Character {\n id: 10,\n name: \"The Lady of the Lake\".to_string(),\n role: \"Mystical Guardian\".to_string(),\n description: \"A mysterious supernatural figure associated with Avalon, known for giving Arthur the sword Excalibur.\".to_string(),\n vector: [0.00, 0.90, 0.58, 0.88],\n stats: Stats {\n strength: 2,\n courage: 3,\n magic: 5,\n wisdom: 5,\n },\n },\n];\ntable\n .add(characters_to_reader(camelot_schema(), &magical_characters))\n .execute()\n .await\n .unwrap();\n";
export const RsBasicCreateEmptyTable = "let schema = Arc::new(Schema::new(vec![\n Field::new(\"id\", DataType::Int16, false),\n Field::new(\"name\", DataType::Utf8, false),\n Field::new(\"role\", DataType::Utf8, false),\n Field::new(\"description\", DataType::Utf8, false),\n Field::new(\n \"vector\",\n DataType::FixedSizeList(Arc::new(Field::new(\"item\", DataType::Float32, true)), 4),\n false,\n ),\n Field::new(\n \"stats\",\n DataType::Struct(arrow_schema::Fields::from(vec![\n Arc::new(Field::new(\"strength\", DataType::Int8, false)),\n Arc::new(Field::new(\"courage\", DataType::Int8, false)),\n Arc::new(Field::new(\"magic\", DataType::Int8, false)),\n Arc::new(Field::new(\"wisdom\", DataType::Int8, false)),\n ])),\n false,\n ),\n]));\ndb.create_empty_table(\"camelot_empty\", schema)\n .mode(CreateTableMode::Overwrite)\n .execute()\n .await\n .unwrap();\n";
export const RsBasicCreateTable = "let mut table = db\n .create_table(\"camelot\", characters_to_reader(schema.clone(), &data))\n .mode(CreateTableMode::Overwrite)\n .execute()\n .await\n .unwrap();\n";
export const RsBasicDeleteRows = "table.delete(\"role = 'Traitor Knight'\").await.unwrap();\n";
export const RsBasicDropColumns = "table.drop_columns(&[\"power\"]).await.unwrap();\n";
export const RsBasicDropTable = "db.drop_table(\"camelot\", &[]).await.unwrap();\n";
export const RsBasicImports = "use arrow_array::types::Float32Type;\nuse arrow_array::{\n FixedSizeListArray, Int8Array, Int16Array, RecordBatch, RecordBatchIterator, StringArray,\n StructArray,\n};\nuse arrow_schema::{DataType, Field, FieldRef, Schema};\nuse futures_util::TryStreamExt;\nuse lancedb::database::CreateTableMode;\nuse lancedb::query::{ExecutableQuery, QueryBase, Select};\nuse lancedb::{connect, table::NewColumnTransform};\n";
export const RsBasicOpenTable = "table = db.open_table(\"camelot\").execute().await.unwrap();\n";
export const RsBasicVectorSearch = "let query_vector = [0.03, 0.85, 0.61, 0.90];\nlet result = table\n .query()\n .nearest_to(&query_vector)\n .unwrap()\n .limit(5)\n .execute()\n .await\n .unwrap()\n .try_collect::<Vec<_>>()\n .await\n .unwrap();\nprintln!(\"{result:?}\");\n";
export const RsBasicVectorSearchQ1 = "// Who are the characters similar to \"wizard\"?\nlet query_vector_1 = [0.03, 0.85, 0.61, 0.90];\nlet r1 = table\n .query()\n .nearest_to(&query_vector_1)\n .unwrap()\n .limit(5)\n .select(Select::Columns(vec![\n \"name\".to_string(),\n \"role\".to_string(),\n \"description\".to_string(),\n ]))\n .execute()\n .await\n .unwrap()\n .try_collect::<Vec<_>>()\n .await\n .unwrap();\nprintln!(\"{r1:?}\");\n";
export const RsBasicVectorSearchQ2 = "// Who are the characters similar to \"wizard\" with high magic stats?\nlet query_vector_2 = [0.03, 0.85, 0.61, 0.90];\nlet r2 = table\n .query()\n .nearest_to(&query_vector_2)\n .unwrap()\n .only_if(\"stats.magic > 3\")\n .select(Select::Columns(vec![\n \"name\".to_string(),\n \"role\".to_string(),\n \"description\".to_string(),\n ]))\n .limit(5)\n .execute()\n .await\n .unwrap()\n .try_collect::<Vec<_>>()\n .await\n .unwrap();\nprintln!(\"{r2:?}\");\n";
export const RsBasicVectorSearchQ3 = "// Who are the strongest characters?\nlet r3 = table\n .query()\n .only_if(\"stats.strength > 3\")\n .select(Select::Columns(vec![\n \"name\".to_string(),\n \"role\".to_string(),\n \"description\".to_string(),\n ]))\n .limit(5)\n .execute()\n .await\n .unwrap()\n .try_collect::<Vec<_>>()\n .await\n .unwrap();\nprintln!(\"{r3:?}\");\n";
export const RsBasicVectorSearchQ4 = "// Who are the strongest characters?\nlet r4 = table\n .query()\n .select(Select::Columns(vec![\n \"name\".to_string(),\n \"role\".to_string(),\n \"description\".to_string(),\n \"power\".to_string(),\n ]))\n .execute()\n .await\n .unwrap()\n .try_collect::<Vec<_>>()\n .await\n .unwrap();\nprintln!(\"{r4:?}\");\n";
export const RsDataLoad = "let data: Vec<Character> =\n serde_json::from_str(&fs::read_to_string(camelot_json_path()).unwrap()).unwrap();\n";