Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc(javascript): minor improvement on docs for working with tables #736

Merged
merged 5 commits into from
Dec 21, 2023
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
39 changes: 27 additions & 12 deletions docs/src/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)."

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/src/guides/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 28 additions & 17 deletions docs/src/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
```


Expand Down Expand Up @@ -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.
Loading