diff --git a/docs/src/basic.md b/docs/src/basic.md index 33bbbf3ab..7d8850b3f 100644 --- a/docs/src/basic.md +++ b/docs/src/basic.md @@ -64,18 +64,26 @@ We'll cover the basics of using LanceDB on your local machine in this section. tbl = db.create_table("table_from_df", data=df) ``` + !!! warning + + If the table already exists, LanceDB will raise an error by default. + If you want to overwrite the table, you can pass in `mode="overwrite"` + to the `createTable` function. + === "Javascript" ```javascript - const tb = await db.createTable("my_table", - data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0}, - {"vector": [5.9, 26.5], "item": "bar", "price": 20.0}]) + const tb = await db.createTable( + "myTable", + [{"vector": [3.1, 4.1], "item": "foo", "price": 10.0}, + {"vector": [5.9, 26.5], "item": "bar", "price": 20.0}]) ``` - -!!! warning - If the table already exists, LanceDB will raise an error by default. - If you want to overwrite the table, you can pass in `mode="overwrite"` - to the `createTable` function. + !!! warning + + If the table already exists, LanceDB will raise an error by default. + If you want to overwrite the table, you can pass in `"overwrite"` + to the `createTable` function like this: `await con.createTable(tableName, data, { writeMode: WriteMode.Overwrite })` + ??? info "Under the hood, LanceDB is converting the input data into an Apache Arrow table and persisting it to disk in [Lance format](https://www.github.com/lancedb/lance)." @@ -108,7 +116,7 @@ Once created, you can open a table using the following code: === "Javascript" ```javascript - const tbl = await db.openTable("my_table"); + const tbl = await db.openTable("myTable"); ``` If you forget the name of your table, you can always get a listing of all table names: @@ -194,10 +202,17 @@ Use the `drop_table()` method on the database to remove a table. db.drop_table("my_table") ``` -This permanently removes the table and is not recoverable, unlike deleting rows. -By default, if the table does not exist an exception is raised. To suppress this, -you can pass in `ignore_missing=True`. + This permanently removes the table and is not recoverable, unlike deleting rows. + By default, if the table does not exist an exception is raised. To suppress this, + you can pass in `ignore_missing=True`. + +=== "JavaScript" + ```javascript + await db.dropTable('myTable') + ``` + This permanently removes the table and is not recoverable, unlike deleting rows. + If the table does not exist an exception is raised. ## What's next diff --git a/docs/src/guides/tables.md b/docs/src/guides/tables.md index d1428c5cc..7b8f958d2 100644 --- a/docs/src/guides/tables.md +++ b/docs/src/guides/tables.md @@ -201,8 +201,8 @@ A Table is a collection of Records in a LanceDB Database. You can follow along o ```javascript data const tb = await db.createTable("my_table", - data=[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0}, - {"vector": [5.9, 26.5], "item": "bar", "price": 20.0}]) + [{"vector": [3.1, 4.1], "item": "foo", "price": 10.0}, + {"vector": [5.9, 26.5], "item": "bar", "price": 20.0}]) ``` !!! info "Note" diff --git a/docs/src/sql.md b/docs/src/sql.md index ef1b9b526..815860b58 100644 --- a/docs/src/sql.md +++ b/docs/src/sql.md @@ -22,7 +22,7 @@ import numpy as np uri = "data/sample-lancedb" db = lancedb.connect(uri) -data = [{"vector": row, "item": f"item {i}"} +data = [{"vector": row, "item": f"item {i}", "id": i} for i, row in enumerate(np.random.random((10_000, 2)).astype('int'))] tbl = db.create_table("my_vectors", data=data) @@ -35,33 +35,25 @@ const db = await vectordb.connect('data/sample-lancedb') let data = [] for (let i = 0; i < 10_000; i++) { - data.push({vector: Array(1536).fill(i), id: `${i}`, content: "", longId: `${i}`},) + data.push({vector: Array(1536).fill(i), id: i, item: `item ${i}`, strId: `${i}`}) } -const tbl = await db.createTable('my_vectors', data) +const tbl = await db.createTable('myVectors', data) ``` --> === "Python" ```python tbl.search([100, 102]) \ - .where("""( - (label IN [10, 20]) - AND - (note.email IS NOT NULL) - ) OR NOT note.created - """) - + .where("(item IN ('item 0', 'item 2')) AND (id > 10)") \ + .to_arrow() ``` + === "Javascript" ```javascript - tbl.search([100, 102]) - .where(`( - (label IN [10, 20]) - AND - (note.email IS NOT NULL) - ) OR NOT note.created - `) + await tbl.search(Array(1536).fill(0)) + .where("(item IN ('item 0', 'item 2')) AND (id > 10)") + .execute() ``` @@ -118,3 +110,22 @@ The mapping from SQL types to Arrow types is: [^1]: See precision mapping in previous table. + +## Filtering without Vector Search + +You can also filter your data without search. + +=== "Python" + ```python + tbl.search().where("id=10").limit(10).to_arrow() + ``` + +=== "JavaScript" + ```javascript + await tbl.where('id=10').limit(10).execute() + ``` + +!!! warning + If your table is large, this could potentially return a very large + amount of data. Please be sure to use a `limit` clause unless + you're sure you want to return the whole result set.