Skip to content

Commit

Permalink
Coffee search example: rebuild db during docker build and add more do…
Browse files Browse the repository at this point in the history
…cumentation.
  • Loading branch information
ignatz committed Nov 20, 2024
1 parent b004188 commit f0133fd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ A simple styled Blog example with UIs both for web and Flutter:
</picture>
</p>

#### Coffee Search

A very small web app demonstrating vector search and custom JS/TS endpoints.

#### First App Tutorial

The code for the [tutorial](https://trailbase.io/getting-started/first-app).
Expand Down
23 changes: 16 additions & 7 deletions examples/coffeesearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
FROM trailbase/trailbase:0.2.1 AS base

COPY traildepot /app/traildepot
COPY dist /app/public
FROM trailbase/trailbase:0.2.2 AS base

USER root

RUN mkdir -p /app/traildepot/data
RUN chown -R trailbase /app/traildepot/data
RUN chmod +w /app/traildepot/data
RUN apk add --no-cache sqlite

# TODO: Add a dedicated build step, both for (re)building the database and
# building the web app.

COPY dist /app/public
COPY traildepot /app/traildepot
COPY arabica_data_cleaned.csv /app/
COPY import.sql /app/

# Rebuild the database.
WORKDIR /app
RUN mkdir -p /app/traildepot/data
RUN rm -rf /app/traildepot/data/*
RUN cat import.sql | sqlite3 traildepot/data/main.db

RUN chown -R trailbase /app/traildepot/data
USER trailbase

EXPOSE 4000
Expand Down
17 changes: 15 additions & 2 deletions examples/coffeesearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ search to build a coffee search.
To import the coffee data from CSV, run:

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

To build the web app

```bash
$ pnpm i
$ pnpm build
```

Finally, to build the docker container:

```
$ docker build . -t coffee && docker run -p 4001:4000 coffee
```

## Reference
Expand Down
2 changes: 1 addition & 1 deletion examples/coffeesearch/traildepot/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ addRoute(
FROM
coffee
WHERE
Aroma IS NOT NULL
embedding IS NOT NULL
ORDER BY
vector_distance_cos(embedding, '[${aroma}, ${flavor}, ${acidity}, ${sweetness}]')
LIMIT 100
Expand Down

0 comments on commit f0133fd

Please sign in to comment.