Skip to content

Commit

Permalink
Reference more code artifacts directly reducing duplication in the co…
Browse files Browse the repository at this point in the history
…ffee tutorial.
  • Loading branch information
ignatz committed Nov 22, 2024
1 parent 1587a32 commit a466bd5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
42 changes: 9 additions & 33 deletions docs/src/content/docs/getting-started/first-ui-app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,14 @@ We'll use the `sqlite3` CLI[^1] directly to import
`examples/coffeesearch/arabica_data_cleaned.csv` with the following SQL
script:

```sql
-- First create the strictly typed "coffee" table.
CREATE TABLE IF NOT EXISTS coffee (
Species TEXT,
Owner TEXT,

Aroma REAL,
Flavor REAL,
Acidity REAL,
Sweetness REAL,

embedding BLOB
) STRICT;

-- Then import the data into a "temporary" table.
.mode csv
.import arabica_data_cleaned.csv temporary

-- Then import the temporary data into the "coffee" table.
INSERT INTO coffee (Species, Owner, Aroma, Flavor, Acidity, Sweetness)
SELECT
Species,
Owner,

CAST(Aroma AS REAL) AS Aroma,
CAST(Flavor AS REAL) AS Flavor,
CAST(Acidity AS REAL) AS Acidity,
CAST(Sweetness AS REAL) AS Sweetness
FROM temporary;

-- And clean up.
DROP TABLE temporary;
```
import importScript from "../../../../../examples/coffeesearch/import.sql?raw";

<Code
code={importScript}
lang="sql"
title={"examples/coffeesearch/import.sql"}
mark={[]}
/>

Note that we didn't initialize the vector `embedding`. This is merely because
`sqlite3` doesn't have the necessary extensions built-in.
Expand All @@ -82,6 +57,7 @@ From within the `example/coffeesearch` directory, you can execute the script
above and import the coffee data by running:

```bash
$ mkdir -p traildepot/data
$ cat import.sql | sqlite3 traildepot/data/main.db -
```

Expand Down
27 changes: 13 additions & 14 deletions examples/coffeesearch/import.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Create table if it doesn't exist.
CREATE TABLE IF NOT EXISTS coffee (
-- First create the strictly typed "coffee" table.
CREATE TABLE coffee (
Species TEXT,
Owner TEXT,

Expand All @@ -11,22 +11,21 @@ CREATE TABLE IF NOT EXISTS coffee (
embedding BLOB
) STRICT;

-- Go on to import data.
DROP TABLE IF EXISTS temporary;

-- Then import the data into a "temporary" table.
.mode csv
.import arabica_data_cleaned.csv temporary

-- Then import the un-typed temporary data into the typed "coffee" table.
INSERT INTO coffee (Species, Owner, Aroma, Flavor, Acidity, Sweetness)
SELECT
Species,
Owner,
SELECT
Species,
Owner,

CAST(Aroma AS REAL) AS Aroma,
CAST(Flavor AS REAL) AS Flavor,
CAST(Acidity AS REAL) AS Acidity,
CAST(Sweetness AS REAL) AS Sweetness
FROM temporary;
CAST(Aroma AS REAL) AS Aroma,
CAST(Flavor AS REAL) AS Flavor,
CAST(Acidity AS REAL) AS Acidity,
CAST(Sweetness AS REAL) AS Sweetness
FROM temporary;

-- Clean up.
-- And clean up.
DROP TABLE temporary;

0 comments on commit a466bd5

Please sign in to comment.