mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 22:26:53 +00:00
A broad documentation pass across the areas LanceDB Enterprise and Embedded diverge on most: **Data Curation** -- GPU Function execution, Slurm scheduling (and what Slurm is, for readers new to it), blob late materialization as its own page, joins, aggregation/profiling, sampling, near-duplicate detection, chunking, distributed shuffle, and IVF-partition clustering. **Feature Engineering** -- computed columns and materialized views, restructured to lead with the Function-based path and show the SQL form side by side with Python throughout; a single Auto Refresh page instead of duplicating scheduling details on every refresh page; adaptive execution; checkpointing; GPU and Slurm placement for refresh workers; a Training Cache page for the PyTorch data loader's automatic cache benefit. **Security & Governance** -- an Audit Log reference (schema, access, grants), Secrets promoted to an ordinary catalog object with their own SQL DDL and a vending/rotation guide, and privilege-table fixes verified against the authorization source. **Deployment & Maintenance** -- Horizontal Scaling and OpenTelemetry moved into a real Deployment area; Automated Cleanup folded into Intelligent Auto-Maintenance (every other maintenance decision already lived there); RTE Compaction and Advanced Conflict Resolution documented in depth. **Landing page** -- the Enterprise feature comparison table reorganized (several redundant or stale rows removed, several new areas added), and the "why Enterprise" bullets replaced with ones tied to a concrete page (Performance, Scale, Fault tolerance, Multicloud deployment, Simplify operations) instead of vague promises. Plus a full pass addressing lancedb-gatekeeper's review: a real test-safety bug (a quickstart test could silently overwrite and delete a deployment's own `frames` table), a fabricated SQL statement with no backing implementation, an actual dedup-guarantee bug in `take_row_ids`, and dozens of documentation-accuracy fixes verified against source rather than taken on faith -- each either fixed, or left with an explicit note on why it needs a feature or deployment owner's sign-off instead of being guessed at. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018PXMCbRH6i5w47TsjeEUMT --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
229 lines
6.6 KiB
Python
229 lines
6.6 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
|
|
|
|
|
|
def test_vector_search():
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import lancedb
|
|
|
|
with TemporaryDirectory(prefix="lancedb-search-") as uri:
|
|
db = lancedb.connect(uri)
|
|
# --8<-- [start:vector_search]
|
|
table = db.create_table(
|
|
"documents",
|
|
[
|
|
{
|
|
"id": 1,
|
|
"text": "A puppy playing in the park",
|
|
"category": "animals",
|
|
"vector": [1.0, 0.0],
|
|
},
|
|
{
|
|
"id": 2,
|
|
"text": "A dog resting at home",
|
|
"category": "animals",
|
|
"vector": [0.9, 0.1],
|
|
},
|
|
{
|
|
"id": 3,
|
|
"text": "A guide to growing tomatoes",
|
|
"category": "gardening",
|
|
"vector": [0.0, 1.0],
|
|
},
|
|
],
|
|
)
|
|
rows = (
|
|
table.search([1.0, 0.0])
|
|
.distance_type("l2")
|
|
.select(["id", "text", "_distance"])
|
|
.limit(2)
|
|
.to_list()
|
|
)
|
|
print(rows)
|
|
# --8<-- [end:vector_search]
|
|
|
|
assert [row["id"] for row in rows] == [1, 2]
|
|
assert rows[0]["_distance"] == 0.0
|
|
|
|
|
|
def test_text_search():
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import lancedb
|
|
from lancedb.index import FTS
|
|
|
|
with TemporaryDirectory(prefix="lancedb-search-") as uri:
|
|
db = lancedb.connect(uri)
|
|
# --8<-- [start:text_search]
|
|
table = db.create_table(
|
|
"documents",
|
|
[
|
|
{
|
|
"id": 1,
|
|
"text": "A puppy playing in the park",
|
|
"category": "animals",
|
|
},
|
|
{
|
|
"id": 2,
|
|
"text": "A dog resting at home",
|
|
"category": "animals",
|
|
},
|
|
{
|
|
"id": 3,
|
|
"text": "A guide to growing tomatoes",
|
|
"category": "gardening",
|
|
},
|
|
],
|
|
)
|
|
table.create_index("text", config=FTS())
|
|
rows = (
|
|
table.search("puppy", query_type="fts", fts_columns="text")
|
|
.select(["id", "text", "_score"])
|
|
.limit(2)
|
|
.to_list()
|
|
)
|
|
print(rows)
|
|
# --8<-- [end:text_search]
|
|
|
|
assert [row["id"] for row in rows] == [1]
|
|
assert rows[0]["_score"] > 0
|
|
|
|
|
|
def test_hybrid_search():
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import lancedb
|
|
from lancedb.index import FTS
|
|
|
|
with TemporaryDirectory(prefix="lancedb-search-") as uri:
|
|
db = lancedb.connect(uri)
|
|
# --8<-- [start:hybrid_search]
|
|
table = db.create_table(
|
|
"documents",
|
|
[
|
|
{
|
|
"id": 1,
|
|
"text": "A puppy playing in the park",
|
|
"category": "animals",
|
|
"vector": [1.0, 0.0],
|
|
},
|
|
{
|
|
"id": 2,
|
|
"text": "A dog resting at home",
|
|
"category": "animals",
|
|
"vector": [0.9, 0.1],
|
|
},
|
|
{
|
|
"id": 3,
|
|
"text": "A guide to growing tomatoes",
|
|
"category": "gardening",
|
|
"vector": [0.0, 1.0],
|
|
},
|
|
],
|
|
)
|
|
from lancedb.rerankers import RRFReranker
|
|
|
|
table.create_index("text", config=FTS())
|
|
rows = (
|
|
table.search(
|
|
query_type="hybrid", vector_column_name="vector", fts_columns="text"
|
|
)
|
|
.vector([1.0, 0.0])
|
|
.text("puppy")
|
|
.rerank(RRFReranker())
|
|
.limit(2)
|
|
.to_list()
|
|
)
|
|
print(rows)
|
|
# --8<-- [end:hybrid_search]
|
|
|
|
assert [row["id"] for row in rows] == [1, 2]
|
|
assert rows[0]["_relevance_score"] > rows[1]["_relevance_score"]
|
|
|
|
|
|
def test_filter_search():
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import lancedb
|
|
|
|
with TemporaryDirectory(prefix="lancedb-search-") as uri:
|
|
db = lancedb.connect(uri)
|
|
# --8<-- [start:filter_search]
|
|
table = db.create_table(
|
|
"documents",
|
|
[
|
|
{
|
|
"id": 1,
|
|
"text": "A puppy playing in the park",
|
|
"category": "animals",
|
|
"vector": [1.0, 0.0],
|
|
},
|
|
{
|
|
"id": 2,
|
|
"text": "A dog resting at home",
|
|
"category": "animals",
|
|
"vector": [0.9, 0.1],
|
|
},
|
|
{
|
|
"id": 3,
|
|
"text": "A guide to growing tomatoes",
|
|
"category": "gardening",
|
|
"vector": [0.0, 1.0],
|
|
},
|
|
],
|
|
)
|
|
rows = (
|
|
table.search([0.0, 1.0])
|
|
.where("category = 'animals'", prefilter=True)
|
|
.select(["id", "text", "category", "_distance"])
|
|
.limit(2)
|
|
.to_list()
|
|
)
|
|
print(rows)
|
|
# --8<-- [end:filter_search]
|
|
|
|
assert {row["id"] for row in rows} == {1, 2}
|
|
assert all(row["category"] == "animals" for row in rows)
|
|
|
|
|
|
def test_query_plan():
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import lancedb
|
|
|
|
with TemporaryDirectory(prefix="lancedb-search-") as uri:
|
|
db = lancedb.connect(uri)
|
|
# --8<-- [start:query_plan]
|
|
table = db.create_table(
|
|
"documents",
|
|
[
|
|
{
|
|
"id": 1,
|
|
"text": "A puppy playing in the park",
|
|
"category": "animals",
|
|
"vector": [1.0, 0.0],
|
|
},
|
|
{
|
|
"id": 2,
|
|
"text": "A dog resting at home",
|
|
"category": "animals",
|
|
"vector": [0.9, 0.1],
|
|
},
|
|
{
|
|
"id": 3,
|
|
"text": "A guide to growing tomatoes",
|
|
"category": "gardening",
|
|
"vector": [0.0, 1.0],
|
|
},
|
|
],
|
|
)
|
|
query = table.search([1.0, 0.0]).select(["id", "text", "_distance"]).limit(2)
|
|
print("Plan:", query.explain_plan())
|
|
print("Measured execution:", query.analyze_plan())
|
|
rows = query.to_list()
|
|
print(rows)
|
|
# --8<-- [end:query_plan]
|
|
|
|
assert [row["id"] for row in rows] == [1, 2]
|