From 8d3825244d2e9d50f87e0f69a049a72b47d250c2 Mon Sep 17 00:00:00 2001 From: prrao87 Date: Fri, 30 Oct 2026 10:33:31 -0400 Subject: [PATCH] docs: add Python and Rust tabs to the home page example The home page showed only the Python example. Add a Rust tab whose code comes from a new in-memory quickstart section of embedded_query.rs, so CI compiles and runs it like the other Rust snippets. --- crates/lance-csr/examples/embedded_query.rs | 42 +++++++++++++++- docs/index.md | 56 ++++++++++++--------- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/crates/lance-csr/examples/embedded_query.rs b/crates/lance-csr/examples/embedded_query.rs index ba9e86d..6cb6493 100644 --- a/crates/lance-csr/examples/embedded_query.rs +++ b/crates/lance-csr/examples/embedded_query.rs @@ -2,7 +2,8 @@ //! //! Writes a small social graph as two Lance datasets in a temporary directory, opens //! them in a CSR-backed engine, runs a two-hop query, appends an edge and picks it up -//! with `refresh()`, and runs a query under a deadline. The documentation includes this +//! with `refresh()`, runs a query under a deadline, and repeats the home page's in-memory +//! Arrow example. The documentation includes this //! file section by section (the `--8<--` markers), so keep it compiling and its printed //! output in step. //! @@ -15,7 +16,7 @@ use std::sync::Arc; use std::time::Duration; use arrow::util::pretty::print_batches; -use arrow_array::{Int64Array, RecordBatch, RecordBatchIterator, StringArray}; +use arrow_array::{ArrayRef, Int64Array, RecordBatch, RecordBatchIterator, StringArray}; use arrow_schema::{DataType, Field, Schema}; use lance::dataset::{Dataset, WriteMode, WriteParams}; use lance_csr::query::with_execution_deadline; @@ -140,5 +141,42 @@ async fn main() -> lance_csr::Result<()> { // | 16 | // +-------+ // --8<-- [end:timeout] + + // --8<-- [start:quickstart] + let config = GraphConfig::builder() + .node_table("Person", "id") + .rel_table("KNOWS", "Person", "Person", "src", "dst") + .build()?; + let person = RecordBatch::try_from_iter([ + ("id", Arc::new(Int64Array::from(vec![1, 2, 3])) as ArrayRef), + ( + "name", + Arc::new(StringArray::from(vec!["Alice", "Bob", "Carol"])) as _, + ), + ])?; + let knows = RecordBatch::try_from_iter([ + ("src", Arc::new(Int64Array::from(vec![1, 2])) as ArrayRef), + ("dst", Arc::new(Int64Array::from(vec![2, 3])) as _), + ])?; + let sources = HashMap::from([ + ("Person".to_string(), EngineSource::Arrow(person)), + ("KNOWS".to_string(), EngineSource::Arrow(knows)), + ]); + let engine = CypherEngine::new(config, sources, true).await?; + let result = engine + .execute( + "MATCH (a:Person {name: 'Alice'})-[:KNOWS*1..2]->(b) \ + RETURN b.name AS friend ORDER BY friend", + HashMap::new(), + ) + .await?; + print_batches(&[result])?; + // +--------+ + // | friend | + // +--------+ + // | Bob | + // | Carol | + // +--------+ + // --8<-- [end:quickstart] Ok(()) } diff --git a/docs/index.md b/docs/index.md index c3e620c..a27133b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,30 +15,38 @@ title: Home no server to operate. Its distinguishing feature is a **compressed sparse row (CSR) adjacency index** that turns each relationship hop from a hash join into an array lookup, which is what makes multi-hop traversals fast. -```python -import pyarrow as pa -from lance_csr import CypherEngine, GraphConfig - -config = ( - GraphConfig.builder() - .node_table("Person", "id") - .rel_table("KNOWS", "Person", "Person", "src", "dst") - .build() -) -engine = CypherEngine( - config, - { - "Person": pa.table({"id": [1, 2, 3], "name": ["Alice", "Bob", "Carol"]}), - "KNOWS": pa.table({"src": [1, 2], "dst": [2, 3]}), - }, - use_csr=True, -) -result = engine.execute( - "MATCH (a:Person {name: 'Alice'})-[:KNOWS*1..2]->(b) " - "RETURN b.name AS friend ORDER BY friend" -) -print(result.to_pylist()) # [{'friend': 'Bob'}, {'friend': 'Carol'}] -``` +=== "Python" + + ```python + import pyarrow as pa + from lance_csr import CypherEngine, GraphConfig + + config = ( + GraphConfig.builder() + .node_table("Person", "id") + .rel_table("KNOWS", "Person", "Person", "src", "dst") + .build() + ) + engine = CypherEngine( + config, + { + "Person": pa.table({"id": [1, 2, 3], "name": ["Alice", "Bob", "Carol"]}), + "KNOWS": pa.table({"src": [1, 2], "dst": [2, 3]}), + }, + use_csr=True, + ) + result = engine.execute( + "MATCH (a:Person {name: 'Alice'})-[:KNOWS*1..2]->(b) " + "RETURN b.name AS friend ORDER BY friend" + ) + print(result.to_pylist()) # [{'friend': 'Bob'}, {'friend': 'Carol'}] + ``` + +=== "Rust" + + ```rust + --8<-- "crates/lance-csr/examples/embedded_query.rs:quickstart" + ```