mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-13 15:22:30 +00:00
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>
173 lines
23 KiB
Plaintext
173 lines
23 KiB
Plaintext
{/* Auto-generated by scripts/mdx_snippets_gen.py. Do not edit manually. */}
|
|
|
|
export const PyBasicFts = "uri = \"data/sample-lancedb\"\ndb = lancedb.connect(uri)\n\ntable = db.create_table(\n \"my_table_fts\",\n data=[\n {\"vector\": [3.1, 4.1], \"text\": \"Frodo was a happy puppy\"},\n {\"vector\": [5.9, 26.5], \"text\": \"There are several kittens playing\"},\n ],\n mode=\"overwrite\",\n)\n\ntable.create_fts_index(\"text\")\ntable.search(\"puppy\").limit(10).select([\"text\"]).to_list()\n# [{'text': 'Frodo was a happy puppy', '_score': 0.6931471824645996}]\n# ...\n";
|
|
|
|
export const PyBasicFtsAsync = "uri = \"data/sample-lancedb\"\nasync_db = await lancedb.connect_async(uri)\n\nasync_tbl = await async_db.create_table(\n \"my_table_fts_async\",\n data=[\n {\"vector\": [3.1, 4.1], \"text\": \"Frodo was a happy puppy\"},\n {\"vector\": [5.9, 26.5], \"text\": \"There are several kittens playing\"},\n ],\n mode=\"overwrite\",\n)\n\n# async API uses our native FTS algorithm\nawait async_tbl.create_index(\"text\", config=FTS())\nawait (await async_tbl.search(\"puppy\")).select([\"text\"]).limit(10).to_list()\n# [{'text': 'Frodo was a happy puppy', '_score': 0.6931471824645996}]\n# ...\n";
|
|
|
|
export const PyBasicHybridSearch = "data = [\n {\"text\": \"rebel spaceships striking from a hidden base\"},\n {\"text\": \"have won their first victory against the evil Galactic Empire\"},\n {\"text\": \"during the battle rebel spies managed to steal secret plans\"},\n {\"text\": \"to the Empire's ultimate weapon the Death Star\"},\n]\nuri = \"data/sample-lancedb\"\ndb = lancedb.connect(uri)\ntable = db.create_table(\"documents\", schema=Documents)\n# ingest docs with auto-vectorization\ntable.add(data)\n# Create a fts index before the hybrid search\ntable.create_fts_index(\"text\")\n# hybrid search with default re-ranker\ntable.search(\"flower moon\", query_type=\"hybrid\").to_pandas()\n";
|
|
|
|
export const PyBasicHybridSearchAsync = "uri = \"data/sample-lancedb\"\nasync_db = await lancedb.connect_async(uri)\ndata = [\n {\"text\": \"rebel spaceships striking from a hidden base\"},\n {\"text\": \"have won their first victory against the evil Galactic Empire\"},\n {\"text\": \"during the battle rebel spies managed to steal secret plans\"},\n {\"text\": \"to the Empire's ultimate weapon the Death Star\"},\n]\nasync_tbl = await async_db.create_table(\"documents_async\", schema=Documents)\n# ingest docs with auto-vectorization\nawait async_tbl.add(data)\n# Create a fts index before the hybrid search\nawait async_tbl.create_index(\"text\", config=FTS())\ntext_query = \"flower moon\"\n# hybrid search with default re-ranker\nawait (await async_tbl.search(\"flower moon\", query_type=\"hybrid\")).to_pandas()\n";
|
|
|
|
export const PyBatchSearch = "# Load a batch of query embeddings\nquery_dataset = load_dataset(\n \"sunhaozhepy/ag_news_sbert_keywords_embeddings\", split=\"test[5000:5005]\"\n)\nquery_embeds = query_dataset[\"keywords_embeddings\"]\nbatch_results = table.search(query_embeds).limit(5).to_pandas()\nprint(batch_results)\n";
|
|
|
|
export const PyBruteForceSearch = "tbl.search(np.random.random((1536))).limit(3).to_list()\n";
|
|
|
|
export const PyBypassVectorIndex = "table.search(embedding).bypass_vector_index().limit(5).to_pandas()\n";
|
|
|
|
export const PyClassDefinition = "class Metadata(BaseModel):\n source: str\n timestamp: datetime\n\n\nclass Document(BaseModel):\n content: str\n meta: Metadata\n\n\nclass LanceSchema(LanceModel):\n id: str\n vector: Vector(1536)\n payload: Document\n";
|
|
|
|
export const PyClassDocuments = "class Documents(LanceModel):\n vector: Vector(embeddings.ndims()) = embeddings.VectorField()\n text: str = embeddings.SourceField()\n";
|
|
|
|
export const PyConfigureDistanceMetric = "tbl.search(np.random.random((1536))).distance_type(\"cosine\").limit(10).to_list()\n";
|
|
|
|
export const PyCreateTableAsyncWithNestedSchema = "# Let's add 100 sample rows to our dataset\ndata = [\n LanceSchema(\n id=f\"id{i}\",\n vector=np.random.randn(1536),\n payload=Document(\n content=f\"document{i}\",\n meta=Metadata(source=f\"source{i % 10}\", timestamp=datetime.now()),\n ),\n )\n for i in range(100)\n]\n\nasync_tbl = await async_db.create_table(\n \"documents_async\", data=data, mode=\"overwrite\"\n)\n";
|
|
|
|
export const PyCreateTableWithNestedSchema = "# Let's add 100 sample rows to our dataset\ndata = [\n LanceSchema(\n id=f\"id{i}\",\n vector=np.random.randn(1536),\n payload=Document(\n content=f\"document{i}\",\n meta=Metadata(source=f\"source{i % 10}\", timestamp=datetime.now()),\n ),\n )\n for i in range(100)\n]\n\n# Synchronous client\ntbl = db.create_table(\"documents\", data=data, mode=\"overwrite\")\n";
|
|
|
|
export const PyExactVsApproximateDistances = "# Indexed ANN search without refinement (fast, approximate `_distance`)\nfast_results = (\n table.search(embedding)\n .limit(10)\n .to_pandas()\n)\n\n# Recompute distances on full vectors for reranked candidates\nexact_distance_results = (\n table.search(embedding)\n .limit(10)\n .refine_factor(1)\n .to_pandas()\n)\n\n# Rerank a larger candidate set for better recall (higher latency)\nhigher_recall_results = (\n table.search(embedding)\n .limit(10)\n .refine_factor(20)\n .to_pandas()\n)\n";
|
|
|
|
export const PyExhaustiveSearch = "uri = \"data/sample-lancedb\"\ndb = lancedb.connect(uri)\ndata = [\n {\"vector\": row, \"item\": f\"item {i}\"}\n for i, row in enumerate(np.random.random((10_000, 1536)).astype(\"float32\"))\n]\ntbl = db.create_table(\"vector_search\", data=data, mode=\"overwrite\")\ntbl.search(np.random.random((1536))).limit(10).to_list()\n";
|
|
|
|
export const PyExhaustiveSearchAsync = "uri = \"data/sample-lancedb\"\nasync_db = await lancedb.connect_async(uri)\ndata = [\n {\"vector\": row, \"item\": f\"item {i}\"}\n for i, row in enumerate(np.random.random((10_000, 1536)).astype(\"float32\"))\n]\nasync_tbl = await async_db.create_table(\n \"vector_search_async\", data=data, mode=\"overwrite\"\n)\n(await (await async_tbl.search(np.random.random((1536)))).limit(10).to_list())\n";
|
|
|
|
export const PyExhaustiveSearchAsyncCosine = "(\n await (await async_tbl.search(np.random.random((1536))))\n .distance_type(\"cosine\")\n .limit(10)\n .to_list()\n)\n";
|
|
|
|
export const PyExhaustiveSearchCosine = "tbl.search(np.random.random((1536))).distance_type(\"cosine\").limit(10).to_list()\n";
|
|
|
|
export const PyFastSearch = "table.search(embedding, fast_search=True).limit(5).to_pandas()\n";
|
|
|
|
export const PyFtsConfigFolding = "table.create_fts_index(\n \"text\",\n language=\"French\",\n stem=True,\n ascii_folding=True,\n replace=True,\n)\n";
|
|
|
|
export const PyFtsConfigFoldingAsync = "await async_tbl.create_index(\n \"text\", config=FTS(language=\"French\", stem=True, ascii_folding=True)\n)\n";
|
|
|
|
export const PyFtsConfigStem = "table.create_fts_index(\"text\", tokenizer_name=\"en_stem\", replace=True)\n";
|
|
|
|
export const PyFtsConfigStemAsync = "await async_tbl.create_index(\n \"text\", config=FTS(language=\"English\", stem=True, remove_stop_words=True)\n)\n";
|
|
|
|
export const PyFtsIncrementalIndex = "table.add([{\"vector\": [3.1, 4.1], \"text\": \"Frodo was a happy puppy\"}])\ntable.optimize()\n";
|
|
|
|
export const PyFtsIncrementalIndexAsync = "await async_tbl.add([{\"vector\": [3.1, 4.1], \"text\": \"Frodo was a happy puppy\"}])\nawait async_tbl.optimize()\n";
|
|
|
|
export const PyFtsPostfiltering = "table.search(\"puppy\").limit(10).where(\"text='foo'\", prefilter=False).to_list()\n";
|
|
|
|
export const PyFtsPostfilteringAsync = "await (\n (await async_tbl.search(\"puppy\"))\n .limit(10)\n .where(\"text='foo'\")\n .postfilter()\n .to_list()\n)\n";
|
|
|
|
export const PyFtsPrefiltering = "table.search(\"puppy\").limit(10).where(\"text='foo'\", prefilter=True).to_list()\n";
|
|
|
|
export const PyFtsPrefilteringAsync = "await (await async_tbl.search(\"puppy\")).limit(10).where(\"text='foo'\").to_list()\n";
|
|
|
|
export const PyFtsWithPosition = "table.create_fts_index(\"text\", with_position=True, replace=True)\n";
|
|
|
|
export const PyFtsWithPositionAsync = "await async_tbl.create_index(\"text\", config=FTS(with_position=True))\n";
|
|
|
|
export const PyHybridSearchPassVectorText = "vector_query = [0.1, 0.2, 0.3, 0.4, 0.5]\ntext_query = \"flower moon\"\n(\n table.search(query_type=\"hybrid\")\n .vector(vector_query)\n .text(text_query)\n .limit(5)\n .to_pandas()\n)\n";
|
|
|
|
export const PyHybridSearchPassVectorTextAsync = "vector_query = [0.1, 0.2, 0.3, 0.4, 0.5]\ntext_query = \"flower moon\"\nawait (\n async_tbl.query()\n .nearest_to(vector_query)\n .nearest_to_text(text_query)\n .limit(5)\n .to_pandas()\n)\n";
|
|
|
|
export const PyImportDatetime = "from datetime import datetime\n";
|
|
|
|
export const PyImportEmbeddings = "from lancedb.embeddings import get_registry\n";
|
|
|
|
export const PyImportLancedb = "import lancedb\n";
|
|
|
|
export const PyImportLancedbFts = "from lancedb.index import FTS\n";
|
|
|
|
export const PyImportLancedbPydantic = "from lancedb.pydantic import Vector, LanceModel\n";
|
|
|
|
export const PyImportNumpy = "from lancedb.query import BoostQuery, MatchQuery\nimport numpy as np\nimport pyarrow as pa\n";
|
|
|
|
export const PyImportOpenai = "import openai\n";
|
|
|
|
export const PyImportOs = "import os\n";
|
|
|
|
export const PyImportPydanticBaseModel = "from pydantic import BaseModel\n";
|
|
|
|
export const PyIndexNestedColumn = "table.create_index(vector_column_name=\"image.embedding\")\n";
|
|
|
|
export const PyMultivectorSearch = "query_multi = np.random.random(size=(2, 256))\nresults_multi = tbl.search(query_multi).limit(5).to_pandas()\n";
|
|
|
|
export const PyOpenaiEmbeddings = "# Ingest embedding function in LanceDB table\n# Configuring the environment variable OPENAI_API_KEY\nif \"OPENAI_API_KEY\" not in os.environ:\n # OR set the key here as a variable\n openai.api_key = \"sk-...\"\nembeddings = get_registry().get(\"openai\").create()\n";
|
|
|
|
export const PySearchBinaryVectors = "import numpy as np\nimport pyarrow as pa\n\nschema = pa.schema(\n [\n pa.field(\"id\", pa.int64()),\n # for dim=256, lance stores every 8 bits in a byte\n # so the vector field should be a list of 256 / 8 = 32 bytes\n pa.field(\"vector\", pa.list_(pa.uint8(), 32)),\n ]\n)\ntbl = db.create_table(\"my_binary_vectors\", schema=schema)\n\ndata = []\nfor i in range(1024):\n vector = np.random.randint(0, 2, size=256)\n # pack the binary vector into bytes to save space\n packed_vector = np.packbits(vector)\n data.append(\n {\n \"id\": i,\n \"vector\": packed_vector,\n }\n )\ntbl.add(data)\n\nquery = np.random.randint(0, 2, size=256)\npacked_query = np.packbits(query)\ntbl.search(packed_query).distance_type(\"hamming\").to_arrow()\n";
|
|
|
|
export const PySearchDistanceRange = "query = np.random.random(256)\n\n# Search for the vectors within the range of [0.1, 0.5)\ntbl.search(query).distance_range(0.1, 0.5).to_arrow()\n\n# Search for the vectors with the distance less than 0.5\ntbl.search(query).distance_range(upper_bound=0.5).to_arrow()\n\n# Search for the vectors with the distance greater or equal to 0.1\ntbl.search(query).distance_range(lower_bound=0.1).to_arrow()\n";
|
|
|
|
export const PySearchResultAsList = "tbl.search(np.random.randn(1536)).to_list()\n";
|
|
|
|
export const PySearchResultAsPandas = "tbl.search(np.random.randn(1536)).to_pandas()\n";
|
|
|
|
export const PySearchResultAsPandasFlatten1 = "tbl.search(np.random.randn(1536)).to_pandas(flatten=1)\n";
|
|
|
|
export const PySearchResultAsPandasFlattenTrue = "tbl.search(np.random.randn(1536)).to_pandas(flatten=True)\n";
|
|
|
|
export const PySearchResultAsPyarrow = "tbl.search(np.random.randn(1536)).to_arrow()\n";
|
|
|
|
export const PySearchResultAsPydantic = "tbl.search(np.random.randn(1536)).to_pydantic(LanceSchema)\n";
|
|
|
|
export const PySearchResultAsyncAsList = "await (await async_tbl.search(np.random.randn(1536))).to_list()\n";
|
|
|
|
export const PySearchResultAsyncAsPandas = "await (await async_tbl.search(np.random.randn(1536))).to_pandas()\n";
|
|
|
|
export const PySearchResultAsyncAsPyarrow = "await (await async_tbl.search(np.random.randn(1536))).to_arrow()\n";
|
|
|
|
export const PySelectVectorColumn = "import pyarrow as pa\n\nschema = pa.schema([\n pa.field(\"id\", pa.int32()),\n pa.field(\n \"image\",\n pa.struct([pa.field(\"embedding\", pa.list_(pa.float32(), 2))]),\n ),\n])\ntable = db.create_table(\n \"nested\",\n data=[{\"id\": 0, \"image\": {\"embedding\": [0.0, 1.0]}}],\n schema=schema,\n)\n\n# Inferred: the only vector leaf is `image.embedding`.\ntable.search([0.0, 1.0]).limit(1).to_list()\n\n# Explicit: required when more than one vector column matches.\ntable.search([0.0, 1.0], vector_column_name=\"image.embedding\").limit(1).to_list()\n";
|
|
|
|
export const PyVectorSearchPostfilter = "results_post_filtered = (\n table.search(query_embed)\n .where(\"label > 1\", prefilter=False)\n .select([\"text\", \"keywords\", \"label\"])\n .limit(5)\n .to_pandas()\n)\n\nprint(\"Vector search results with post-filter:\")\nprint(results_post_filtered)\n";
|
|
|
|
export const PyVectorSearchPrefilter = "from datasets import load_dataset\n\n# Load query vector from dataset\nquery_dataset = load_dataset(\"sunhaozhepy/ag_news_sbert_keywords_embeddings\", split=\"test[5000:5001]\")\nprint(f\"Query keywords: {query_dataset[0]['keywords']}\")\nquery_embed = query_dataset[\"keywords_embeddings\"][0]\n\n# Open table and perform search\ntable_name = \"lancedb-enterprise-quickstart\"\ntable = db.open_table(table_name)\n\n# Vector search with filters (pre-filtering is the default)\nsearch_results = (\n table.search(query_embed)\n .where(\"label > 2\")\n .select([\"text\", \"keywords\", \"label\"])\n .limit(5)\n .to_pandas()\n)\n\nprint(\"Search results (with pre-filtering):\")\nprint(search_results)\n";
|
|
|
|
export const TsBatchSearch = "// Batch query\nconsole.log(\"Performing batch vector search...\");\nconst batchSize = 5;\nconst queryVectors = Array.from({ length: batchSize }, () =>\n Array.from({ length: dimensions }, () => Math.random() * 2 - 1),\n);\nlet batchQuery = table.search(queryVectors[0]) as lancedb.VectorQuery;\nfor (let i = 1; i < batchSize; i++) {\n batchQuery = batchQuery.addQueryVector(queryVectors[i]);\n}\nconst batchResults = await batchQuery\n .select([\"text\", \"keywords\", \"label\"])\n .limit(5)\n .toArray();\nconsole.log(\"Batch vector search results:\");\nconsole.log(batchResults);\n";
|
|
|
|
export const TsBinarySearch = "const tbl = await db.createTable(\"binary_vectors\", data, {\n mode: \"overwrite\",\n});\nawait tbl.createIndex(\"vector\", {\n config: lancedb.Index.ivfFlat({\n numPartitions: 10,\n distanceType: \"hamming\",\n }),\n});\n\nconst query = Array(32)\n .fill(1)\n .map(() => Math.floor(Math.random() * 255));\nconst results = await tbl.query().nearestTo(query).limit(10).toArray();\n";
|
|
|
|
export const TsBruteForceSearch = "const tbl = await db.openTable(\"my_vectors\");\n\nconst results1 = await tbl.search(Array(128).fill(1.2)).limit(3).toArray();\n";
|
|
|
|
export const TsBypassVectorIndex = "await table\n .query()\n .nearestTo(embedding)\n .bypassVectorIndex()\n .limit(5)\n .toArray();\n";
|
|
|
|
export const TsDistanceRange = "const results3 = await (\n tbl.search(Array(128).fill(1.2)) as lancedb.VectorQuery\n)\n .distanceType(\"cosine\")\n .distanceRange(0.1, 0.2)\n .limit(10)\n .toArray();\n";
|
|
|
|
export const TsExactVsApproximate = "// Indexed ANN search without refinement (fast, approximate `_distance`)\nconst fastResults = await (table.search(embedding) as lancedb.VectorQuery)\n .limit(10)\n .toArray();\n\n// Recompute distances on full vectors for reranked candidates\nconst exactDistanceResults = await (\n table.search(embedding) as lancedb.VectorQuery\n)\n .limit(10)\n .refineFactor(1)\n .toArray();\n\n// Rerank a larger candidate set for better recall (higher latency)\nconst higherRecallResults = await (\n table.search(embedding) as lancedb.VectorQuery\n)\n .limit(10)\n .refineFactor(20)\n .toArray();\n";
|
|
|
|
export const TsFastSearch = "await table\n .query()\n .nearestTo(embedding)\n .fastSearch()\n .limit(5)\n .toArray();\n";
|
|
|
|
export const TsImport = "import * as lancedb from \"@lancedb/lancedb\";\n";
|
|
|
|
export const TsImportBinUtil = "import { Field, FixedSizeList, Int32, Schema, Uint8 } from \"apache-arrow\";\n";
|
|
|
|
export const TsIndexNestedColumn = "await table.createIndex(\"image.embedding\");\n";
|
|
|
|
export const TsIngestBinaryData = "const schema = new Schema([\n new Field(\"id\", new Int32(), true),\n new Field(\"vec\", new FixedSizeList(32, new Field(\"item\", new Uint8()))),\n]);\nconst data = lancedb.makeArrowTable(\n Array(1_000)\n .fill(0)\n .map((_, i) => ({\n // the 256 bits would be store in 32 bytes,\n // if your data is already in this format, you can skip the packBits step\n id: i,\n vec: lancedb.packBits(Array(256).fill(i % 2)),\n })),\n { schema: schema },\n);\n\nconst tbl = await db.createTable(\"binary_table\", data);\nawait tbl.createIndex(\"vec\", {\n config: lancedb.Index.ivfFlat({\n numPartitions: 10,\n distanceType: \"hamming\",\n }),\n});\n";
|
|
|
|
export const TsSearch1 = "const db = await lancedb.connect(databaseDir);\nconst tbl = await db.openTable(\"my_vectors\");\n\nconst results1 = await tbl.search(Array(128).fill(1.2)).limit(10).toArray();\n";
|
|
|
|
export const TsSearch2 = "const results2 = await (\n tbl.search(Array(128).fill(1.2)) as lancedb.VectorQuery\n)\n .distanceType(\"cosine\")\n .limit(10)\n .toArray();\n";
|
|
|
|
export const TsSearchBinaryData = "const query = Array(32)\n .fill(1)\n .map(() => Math.floor(Math.random() * 255));\nconst results = await tbl.query().nearestTo(query).limit(10).toArrow();\n";
|
|
|
|
export const TsSelectVectorColumn = "const table = await db.openTable(\"nested\");\n\n// Inferred: LanceDB finds the single nested vector leaf automatically.\nawait table.query().nearestTo([0.0, 1.0]).limit(1).toArray();\n\n// Explicit: required when more than one vector column matches.\nawait table\n .query()\n .nearestTo([0.0, 1.0])\n .column(\"image.embedding\")\n .limit(1)\n .toArray();\n";
|
|
|
|
export const TsVectorSearchPostfilter = "const vectorResultsWithPostFilter = await (\n table.search(queryEmbed) as lancedb.VectorQuery\n)\n .where(\"label > 2\")\n .postfilter()\n .select([\"text\", \"keywords\", \"label\"])\n .limit(5)\n .toArray();\n\nconsole.log(\"Vector search results with post-filter:\");\nconsole.log(vectorResultsWithPostFilter);\n";
|
|
|
|
export const TsVectorSearchPrefilter = "// Generate a sample 768-dimension embedding vector (typical for BERT-based models)\n// In real applications, you would get this from an embedding model\nconst dimensions = 768;\nconst queryEmbed = Array.from(\n { length: dimensions },\n () => Math.random() * 2 - 1,\n);\n\n// Open table and perform search\nconst tableName = \"lancedb-enterprise-quickstart\";\nconst table = await db.openTable(tableName);\n\n// Vector search with filters (pre-filtering is the default)\nconst vectorResults = await table\n .search(queryEmbed)\n .where(\"label > 2\")\n .select([\"text\", \"keywords\", \"label\"])\n .limit(5)\n .toArray();\n\nconsole.log(\"Search results (with pre-filtering):\");\nconsole.log(vectorResults);\n";
|
|
|
|
export const RsBatchSearch = "// Search multiple query vectors in one call. Each result row carries a\n// `query_index` mapping it back to the query it matched.\nlet mut results = table\n .vector_search(&query_1)?\n .add_query_vector(&query_2)?\n .limit(5)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsBinarySearch = "// Binary vectors use `hamming` distance over the packed uint8 bytes.\nlet query: Arc<dyn Array> = Arc::new(UInt8Array::from(vec![1u8; NUM_BYTES as usize]));\nlet mut results = tbl\n .vector_search(query)?\n .distance_type(DistanceType::Hamming)\n .limit(10)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsBruteForceSearch = "// A plain vector search returns the top-k closest rows.\nlet mut results = table.vector_search(&query_vector)?.limit(3).execute().await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsBypassVectorIndex = "// Force an exhaustive (flat) scan for exact, ground-truth results.\nlet mut results = table\n .vector_search(&query_vector)?\n .bypass_vector_index()\n .limit(5)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsConfigureDistanceMetric = "// Use the same distance metric the index was trained with.\nlet mut results = table\n .vector_search(&query_vector)?\n .distance_type(DistanceType::Cosine)\n .limit(10)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsExactVsApproximate = "// Approximate ANN search (fast, distances may come from the index representation)\nlet mut fast_results = table.vector_search(&query_vector)?.limit(10).execute().await?;\nwhile let Some(batch) = fast_results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n\n// Rerank a larger candidate set on full vectors for better recall\nlet mut refined_results = table\n .vector_search(&query_vector)?\n .limit(10)\n .refine_factor(20)\n .execute()\n .await?;\nwhile let Some(batch) = refined_results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsFastSearch = "// Skip unindexed data for lower latency.\nlet mut results = table\n .vector_search(&query_vector)?\n .fast_search()\n .limit(5)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsSearchDistanceRange = "// Only return rows whose distance falls within [0.1, 0.5).\nlet mut results = table\n .vector_search(&query_vector)?\n .distance_range(Some(0.1), Some(0.5))\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsVectorSearchPostfilter = "// Apply the filter after vector search by calling postfilter().\nlet mut results = table\n .vector_search(&query_vector)?\n .only_if(\"id > 100\")\n .postfilter()\n .select(Select::columns(&[\"id\"]))\n .limit(5)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|
|
export const RsVectorSearchPrefilter = "// Prefiltering is the default: the filter is applied before vector search.\nlet mut results = table\n .vector_search(&query_vector)?\n .only_if(\"id > 100\")\n .select(Select::columns(&[\"id\"]))\n .limit(5)\n .execute()\n .await?;\nwhile let Some(batch) = results.try_next().await? {\n println!(\"{:?}\", batch);\n}\n";
|
|
|