Skip to content

Commit 6bb517a

Browse files
committed
Add a new vector search + Web UI example.
1 parent fb2c5b9 commit 6bb517a

28 files changed

+2764
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ node_modules/
1010

1111
# Dev artifacts
1212
public/
13-
traildepot/

examples/blog/traildepot/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ secrets/
55
uploads/
66

77
!migrations/
8+
9+
trailbase.js
10+
trailbase.d.ts

examples/coffeesearch/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/coffeesearch/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM trailbase/trailbase:0.2.1 AS base
2+
3+
COPY traildepot /app/traildepot
4+
COPY dist /app/public
5+
6+
USER root
7+
8+
RUN mkdir -p /app/traildepot/data
9+
RUN chown -R trailbase /app/traildepot/data
10+
RUN chmod +w /app/traildepot/data
11+
12+
13+
USER trailbase
14+
15+
EXPOSE 4000
16+
ENTRYPOINT ["tini", "--"]
17+
CMD ["/app/trail", "--data-dir", "/app/traildepot", "run", "--address", "0.0.0.0:4000", "--public-dir", "/app/public"]
18+
19+
HEALTHCHECK CMD curl --fail http://localhost:4000/api/healthcheck || exit 1

examples/coffeesearch/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
all: init app
2+
3+
app: dist
4+
pnpm build
5+
6+
init:
7+
mkdir -p traildepot/data; cat import.sql | sqlite3 traildepot/data/main.db -
8+
9+
.PHONY: init

examples/coffeesearch/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Coffee Search
2+
3+
A small web application demonstrating the use of TrailBase and its vector
4+
search to build a coffee search.
5+
6+
To import the coffee data from CSV, run:
7+
8+
```bash
9+
mkdir -p traildepot/data
10+
cat import.sql | sqlite3 traildepot/data/main.db -
11+
```
12+
13+
## Reference
14+
15+
* Coffee data [source](https://github.com/jldbc/coffee-quality-database/blob/master/data/arabica_data_cleaned.csv)

examples/coffeesearch/arabica_data_cleaned.csv

Lines changed: 1318 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
7+
export default tseslint.config(
8+
{ ignores: ['dist'] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ['**/*.{ts,tsx}'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
'react-hooks': reactHooks,
18+
'react-refresh': reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
'react-refresh/only-export-components': [
23+
'warn',
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
},
28+
)

examples/coffeesearch/import.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- Create table if it doesn't exist.
2+
CREATE TABLE IF NOT EXISTS coffee (
3+
Species TEXT,
4+
Owner TEXT,
5+
6+
Aroma REAL,
7+
Flavor REAL,
8+
Acidity REAL,
9+
Sweetness REAL,
10+
11+
embedding BLOB
12+
) STRICT;
13+
14+
-- Empty table for clean import.
15+
DELETE FROM coffee;
16+
17+
-- Go on to import data.
18+
DROP TABLE IF EXISTS temporary;
19+
20+
.mode csv
21+
.import arabica_data_cleaned.csv temporary
22+
23+
INSERT INTO coffee (Species, Owner, Aroma, Flavor, Acidity, Sweetness)
24+
SELECT
25+
Species,
26+
Owner,
27+
28+
CAST(Aroma AS REAL) AS Aroma,
29+
CAST(Flavor AS REAL) AS Flavor,
30+
CAST(Acidity AS REAL) AS Acidity,
31+
CAST(Sweetness AS REAL) AS Sweetness
32+
FROM temporary;
33+
34+
-- Clean up.
35+
DROP TABLE temporary;

examples/coffeesearch/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
7+
<title>Coffee Search</title>
8+
</head>
9+
10+
<body>
11+
<div id="root"></div>
12+
<script type="module" src="/src/main.tsx"></script>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)