Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[Documentation](https://lance-csr.hdclabs.ai/) · [Examples](examples/README.md) ·
[Releases](https://github.com/hyperdimensionalcomputingai/lance-csr/releases) · [Contributing](CONTRIBUTING.md)

lance-csr is a fast graph query engine over [Lance](https://lancedb.github.io/lance/) datasets, built in Rust on
lance-csr is a fast graph query engine over [Lance](https://lance.org/) datasets, built in Rust on
Apache DataFusion, with Python and Node.js bindings. It is a fork of [lance-graph](https://github.com/lance-format/lance-graph)
and a research test bed: it pushes the limits of CSR indexes and DataFusion on top of the Lance format, with the
goal of making multi-hop path traversal fast.
Expand Down
2 changes: 1 addition & 1 deletion crates/lance-csr/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lance-csr

A Cypher graph query engine for [Lance](https://lancedb.github.io/lance/) datasets, built on Apache DataFusion,
A Cypher graph query engine for [Lance](https://lance.org/) datasets, built on Apache DataFusion,
with a CSR (compressed sparse row) adjacency index for fast multi-hop traversal. It interprets Lance datasets or
Arrow tables as property graphs. The [lance-csr Python package](https://pypi.org/project/lance-csr/) wraps this
crate.
Expand Down
2 changes: 1 addition & 1 deletion docs/csr.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ CsrExpandExec: key=follower__id, edges=2417738, take=person[person__name]

To see how many rows a hop actually produced, run `explain(query, analyze=True)`: each operator's line then
carries its runtime metrics, such as `output_rows=` and `elapsed_compute=` (see
[`explain`](cypher.md#explainquery-paramsnone-analyzefalse)).
[`explain`](running-queries.md#explain)).

If such a hop isn't counted in place and the query is slower with `use_csr=True`, the join path is doing the
same work with less overhead. The planner won't switch that hop to a join for you: the fallback covers hops the
Expand Down
739 changes: 243 additions & 496 deletions docs/cypher.md

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions docs/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,9 @@ Source paths below are in `crates/lance-csr/src/`.
with `CsrExpandExec`, the shortest-path search and `ApplyExec` among its extension operators.

`engine.explain(query)` prints the plans from steps 4 to 6, and `engine.explain(query, analyze=True)` runs step 6
and adds each operator's row counts and time (see [`explain`](cypher.md#explainquery-paramsnone-analyzefalse)).

A CALL body is kept as an unoptimized child template. For each incoming row, `ApplyExec` binds its
explicit imports, plans the child, and streams that child's batches. Child `LIMIT` and aggregates
therefore apply separately to each incoming row. The operator retains one outer batch and one child
stream per partition; its children may have their own buffering requirements. Dropping the result
stream drops both owned streams. CALL queries use ordinary planning instead of the engine's template
cache.

Rust callers supplying their own `SessionContext` must install `CsrQueryPlanner` to execute CALL or
other graph extension nodes. Contexts created by `CypherQuery` and `CypherEngine` install it themselves.
and adds each operator's row counts and time (see [`explain`](running-queries.md#explain)). For details on each
extension operator, optimizer rule and custom `SessionContext` setup, see
[DataFusion internals](internals/index.md).

## Joins versus CSR expansion

Expand Down
5 changes: 5 additions & 0 deletions docs/explain_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def main() -> None:
args = parser.parse_args()

csr, joins = people(True), people(False)
show(
"running-queries.md: explain(analyze=True)",
csr,
"MATCH (a:Person {name: 'Alice'})-[:KNOWS]->(b:Person) RETURN b.name",
)
two_hop = "MATCH (a:Person)-[:KNOWS]->(b:Person)-[:KNOWS]->(c:Person {name: 'Dan'}) RETURN a.name"
show("operators.md: CsrExpand, use_csr=True", csr, two_hop)
show("operators.md: CsrExpand, use_csr=False", joins, two_hop)
Expand Down
3 changes: 2 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ than one query against the same data.
## Next steps

- [Graph schema](graph-schema.md): every option of `GraphConfig`.
- [Querying with Cypher](cypher.md): parameters, streaming, `explain()` (with runtime metrics) and the supported Cypher.
- [Running queries](running-queries.md): `CypherEngine`, parameters, streaming, deadlines, `explain()` and tuning.
- [Cypher reference](cypher.md): supported clauses, patterns, path values, expressions and functions.
- [Lance datasets](lance.md): query data on disk without loading it, and pick up new writes with `checkout_latest()`.
- [Using from Rust](rust.md): the same engine as a Rust library.
- [Using from TypeScript](typescript.md): the same engine in Node.js.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ title: Home
# A fast graph query engine on Lance

**lance-csr** is an open source [openCypher](https://opencypher.org/) query engine for graphs stored as
[Lance](https://lancedb.github.io/lance/) datasets or Arrow tables. It is written in Rust on
[Lance](https://lance.org/) datasets or Arrow tables. It is written in Rust on
[Apache DataFusion](https://datafusion.apache.org/), ships as a Python package, a Rust crate and an npm package, and runs on one machine with
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.
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This section is for contributors and for readers who want to know how lance-csr
[Apache DataFusion](https://datafusion.apache.org/) to run graph queries. You don't need any of it to use the engine:
[How it works](../execution.md) gives the short version.

lance-csr's goal is fast multi-hop traversal over data that already lives in [Lance](https://lancedb.github.io/lance/),
lance-csr's goal is fast multi-hop traversal over data that already lives in [Lance](https://lance.org/),
with no import into a graph database and no second copy of the data. DataFusion is a strong relational engine, but a
graph hop written relationally is two hash joins, and a five-hop query is ten of them. lance-csr keeps DataFusion for
everything it already does well (filters, projections, aggregates, sorts, joins, vectorized multi-threaded execution)
Expand Down
57 changes: 9 additions & 48 deletions docs/lance.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lance datasets

[Lance](https://lancedb.github.io/lance/) is a columnar format for ML and multimodal data, with versioning,
[Lance](https://lance.org/) is a columnar format for ML and multimodal data, with versioning,
fast random access and vector indexes. lance-csr can query Lance datasets on disk without loading them into
memory first.

Expand Down Expand Up @@ -95,44 +95,10 @@ What `checkout_latest()` guarantees:
`checkout_latest()` reopens each dataset by its URI with the same `storage_options` it was opened with, so object-store
credentials carry over.

## Repeated queries

`execute()` and `execute_batches()` keep up to 128 query templates per engine snapshot. Reuse the exact
query text with `$name` parameters to reuse parsing, semantic analysis, graph logical planning and
DataFusion logical planning. Every execution binds its own values before optimization and physical planning;
rows and results are never cached. Query text and parameter names/types identify each template, with nulls
separate from non-null values. Least recently used templates are evicted at the limit.

Lists, maps and parameterized `SKIP`/`LIMIT` counts use ordinary planning because their shape or value can
change the plan. Queries whose operators cannot produce a reusable template fall back to ordinary planning. `explain()` plans the current values directly; `explain(..., analyze=True)` plans as `execute()` does, through the cache. A successful `checkout_latest()` starts an empty cache for the
new snapshot, even when no dataset changed; active readers retain their existing plans.
These rules apply with and without CSR. They do not promise a speedup for a particular workload.

## Query parallelism

`CypherEngine(..., target_partitions=None)` keeps DataFusion's default query partitioning. If you have
measured your workload, you can choose a target from 1 to 1024 explicitly:

```python
serial_engine = CypherEngine(
config,
{"Person": lance.dataset("person.lance"), "KNOWS": lance.dataset("knows.lance")},
use_csr=True,
target_partitions=1,
)
print(serial_engine.execute("MATCH (p:Person) RETURN count(*) AS n").to_pylist()) # [{'n': 4}]
serial_engine.checkout_latest() # retains target_partitions=1
```

The target is a planning preference, not a thread or memory limit; operators may use a different number
of partitions. A lower target can help short queries while making larger joins and scans slower. Compare
your full workload in the storage mode you use before choosing a value. The default remains unchanged,
and `checkout_latest()` preserves your choice. Booleans and non-integers other than `None` raise `TypeError`;
zero, negative and out-of-range integers raise `ValueError`.

## Streaming large results

`execute()` returns one table, held in memory. For big outputs, stream:
`execute()` returns one table, held in memory. For big outputs, stream with
[`execute_batches()`](running-queries.md#streaming):

```python
total = 0
Expand Down Expand Up @@ -189,18 +155,13 @@ engine.checkout_latest() # the engine sees the new version

!!! warning "LanceDB bundles its own Lance"

LanceDB doesn't use `pylance` or lance-csr's built-in Lance: each LanceDB release bundles its own copy of the
Lance library, which is often newer than lance-csr's. The Lance format is mostly backwards compatible, so
newer Lance reads what older Lance wrote, but not always the other way around. A LanceDB that bundles a newer
Lance major version may write files, or use format features, that lance-csr's older Lance can't read: opening
or querying the dataset then fails with an error.

It also matters when lance-csr writes. [`write_node_column`](graph-algorithms.md#writing-results-back-to-lance)
and [`optimize_datasets`](#compaction-and-old-versions) commit new versions with lance-csr's Lance, into
datasets that LanceDB also writes. Before upgrading LanceDB, compare the Lance version it bundles (LanceDB's
`Cargo.toml` names it) with the one in lance-csr's
Each LanceDB release bundles its own copy of Lance, often newer than lance-csr's built-in copy. If LanceDB
uses a newer Lance major version, it can write files that lance-csr fails to open, and lance-csr writes
([`write_node_column`](graph-algorithms.md#writing-results-back-to-lance),
[`optimize_datasets`](#compaction-and-old-versions)) commit with lance-csr's Lance version. Before upgrading
LanceDB, compare its bundled Lance version with lance-csr's
[`Cargo.toml`](https://github.com/hyperdimensionalcomputingai/lance-csr/blob/main/crates/lance-csr/Cargo.toml),
and when the major versions differ, try the upgrade on a copy of your tables first.
and test major-version upgrades on a copy of your tables first.

!!! failure "Not supported"

Expand Down
Loading
Loading