mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-13 15:22:57 +00:00
doc: use code snippet for typescript examples (#880)
The typescript code is in a fully function file, that will be run via the CI.
This commit is contained in:
@@ -54,22 +54,18 @@
|
||||
|
||||
=== "Javascript"
|
||||
|
||||
```javascript
|
||||
const lancedb = require("vectordb");
|
||||
```typescript
|
||||
--8<-- "src/basic_legacy.ts:import"
|
||||
|
||||
const uri = "data/sample-lancedb";
|
||||
const db = await lancedb.connect(uri);
|
||||
```
|
||||
--8<-- "src/basic_legacy.ts:open_db"
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust
|
||||
use vectordb::connect;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let uri = "data/sample-lancedb";
|
||||
let db = connect(uri).await?;
|
||||
--8<-- "src/basic.rs:connect"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -105,11 +101,7 @@ If you need a reminder of the uri, you can call `db.uri()`.
|
||||
=== "Javascript"
|
||||
|
||||
```javascript
|
||||
const tbl = await db.createTable(
|
||||
"myTable",
|
||||
[{"vector": [3.1, 4.1], "item": "foo", "price": 10.0},
|
||||
{"vector": [5.9, 26.5], "item": "bar", "price": 20.0}]
|
||||
)
|
||||
--8<-- "src/basic_legacy.ts:create_table"
|
||||
```
|
||||
|
||||
If the table already exists, LanceDB will raise an error by default.
|
||||
@@ -160,10 +152,7 @@ In this case, you can create an empty table and specify the schema.
|
||||
=== "Javascript"
|
||||
|
||||
```typescript
|
||||
import { Schema, Field, FixedSizeList, DataType } from "apache-arrow";
|
||||
|
||||
schema = new Schema([new new Field("vec", new FixedSizeList(2, new Field("item", new Float32())))])
|
||||
tbl = await db.createTable({ name: "empty_table", schema: schema });
|
||||
--8<-- "src/basic_legacy.ts:create_empty_table"
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
@@ -269,7 +258,7 @@ Once you've embedded the query, you can find its nearest neighbors using the fol
|
||||
=== "Javascript"
|
||||
|
||||
```javascript
|
||||
const query = await tbl.search([100, 100]).limit(2).execute();
|
||||
--8<-- "src/basic_legacy.ts:search"
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
@@ -291,13 +280,13 @@ For tables with more than 50K vectors, creating an ANN index is recommended to s
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python
|
||||
```py
|
||||
tbl.create_index()
|
||||
```
|
||||
|
||||
=== "Javascript"
|
||||
|
||||
```javascript
|
||||
```{.typescript .ignore}
|
||||
await tbl.createIndex({})
|
||||
```
|
||||
|
||||
@@ -324,7 +313,7 @@ This can delete any number of rows that match the filter.
|
||||
=== "Javascript"
|
||||
|
||||
```javascript
|
||||
await tbl.delete('item = "fizz"')
|
||||
--8<-- "src/basic_legacy.ts:delete"
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
@@ -362,7 +351,7 @@ Use the `drop_table()` method on the database to remove a table.
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript
|
||||
await db.dropTable('myTable')
|
||||
--8<-- "src/basic_legacy.ts:drop_table"
|
||||
```
|
||||
|
||||
This permanently removes the table and is not recoverable, unlike deleting rows.
|
||||
|
||||
Reference in New Issue
Block a user