Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

docs and default fix for SIE credentials and reranker

Filip Makraduli154929cb133a
diff --git a/examples/wine-recommender/.env.example b/examples/wine-recommender/.env.example
index 38d94db30..6ae73f172 100644
--- a/examples/wine-recommender/.env.example
+++ b/examples/wine-recommender/.env.example
@@ -1,13 +1,38 @@
# Root app environment for `app.py` and the main backend.
# The `wine_picture_detection` folder can also have its own local `.env` for standalone work.
+#
+# Copy this file to `.env` in the same directory before running `docker compose up`:
+# cp .env.example .env
+# Then fill in CLUSTER_URL and API_KEY (see README "Get your SIE credentials" section).
+# --- SIE cluster (required) ---
+# You bring your own SIE cluster. These values come from the SIE dashboard for a
+# managed cluster, or from your local SIE server config if self-hosting.
+# See https://sie.dev/docs/quickstart for setup options.
CLUSTER_URL=https://your-sie-cluster-url
API_KEY=your-sie-api-key
-RERANK_METHOD=standard
+
+# --- Reranker configuration ---
+# "custom" uses SIE `encode` on tasting notes and reviews, then cosine-scores
+# candidates against the user query. Works with the bundled SQLite catalog
+# (which has no per-wine reviews).
+# "standard" uses SIE `score` to rerank candidate reviews against prompt terms.
+# Requires wines to have populated reviews - re-run db_creation to fetch them
+# from Vivino, otherwise every wine will score 0 and matchPercentage will be 0%.
+RERANK_METHOD=custom
SIE_RERANK_MODEL=BAAI/bge-reranker-v2-m3
SIE_EMBEDDING_MODEL=BAAI/bge-m3
RERANK_ALPHA=0.7
CUSTOM_RERANK_A=0.75
CUSTOM_RERANK_NO_REVIEW_PENALTY=0.5
+
+# --- SIE runtime options ---
SIE_GPU=l4-spot
SIE_PROVISION_TIMEOUT_S=900
+
+# --- OpenAI (optional) ---
+# Only required for the /analyze-flavor-prompt endpoint, which turns a
+# natural-language wine description into structure and flavor weights.
+# Get a key at https://platform.openai.com/api-keys.
+# Leave this unset if you don't need the natural-language prompt feature.
+OPENAI_API_KEY=your-openai-api-key
diff --git a/examples/wine-recommender/README.md b/examples/wine-recommender/README.md
index ea07939b2..2adbc06fd 100644
--- a/examples/wine-recommender/README.md
+++ b/examples/wine-recommender/README.md
@@ -27,9 +27,11 @@ The duplicated database files (`wine_flavor.db`) and local `.env` setup are inte
## SIE Features Used
-- `encode` for retrieval embeddings
-- `score` for reranking candidate wines
-- `extract` for OCR-based wine label detection
+- [`encode`](https://sie.dev/docs/encode) for tasting-note and review embeddings in the **custom reranker**
+- [`score`](https://sie.dev/docs/score) for cross-encoder reranking of candidate reviews in the **standard reranker**
+- [`extract`](https://sie.dev/docs/extract) for OCR-based wine label detection
+
+Retrieval itself (the first stage that narrows 5k+ wines down to a candidate set) runs locally with a TF-IDF cosine over structured flavor and taste attributes, so the first-stage retrieval does not call SIE. SIE engages at the reranking and extraction stages.
## Why The OCR Flow Matters
@@ -66,9 +68,33 @@ flowchart TD;
D --> E["Wine identification"];
```
-## Pre-requisite
+## Pre-requisites
+
+### Get your SIE credentials
+
+This demo does not bundle an SIE server - you bring your own. You need:
+
+- **`CLUSTER_URL`**: the URL of a running SIE cluster you can reach from the machine that runs the backend container
+- **`API_KEY`**: a valid API key for that cluster
+
+You can get these either by:
+
+1. **Self-hosting SIE** - see the [SIE quickstart](https://sie.dev/docs/quickstart) to run an SIE server locally or on your own infrastructure, then use that `CLUSTER_URL` and issue yourself an `API_KEY` from the server config
+2. **Using a managed SIE cluster** - grab the `CLUSTER_URL` and `API_KEY` from your SIE dashboard
+
+Background on the SIE primitives this demo uses:
-In order to run this demo, you will need to start the SIE server. Please refer to the [SIE quickstart page](https://sie.dev/docs/quickstart) for detailed instructions
+- [`encode`](https://sie.dev/docs/encode) - dense embeddings for tasting notes and reviews (used by the "custom" reranker)
+- [`score`](https://sie.dev/docs/score) - cross-encoder reranking (used by the "standard" reranker)
+- [`extract`](https://sie.dev/docs/extract) - OCR-style extraction on wine label images
+
+### Optional: OpenAI API key
+
+The `/analyze-flavor-prompt` endpoint turns a natural-language wine description into structure and flavor weights using `gpt-4.1-mini`. This is optional - the rest of the demo works without it. Set `OPENAI_API_KEY` in your `.env` only if you want to use the natural-language prompt feature. Get a key at [platform.openai.com/api-keys](https://platform.openai.com/api-keys).
+
+### Docker and Docker Compose
+
+You need Docker and Docker Compose v2 installed. The backend builds against `python:3.12-slim`, so no local Python setup is required.
## Running the full Demo
@@ -81,6 +107,7 @@ From the repo root:
```bash
cd examples/wine-recommender
+cp .env.example .env # edit .env and fill in CLUSTER_URL and API_KEY
docker compose up --build
```
@@ -99,12 +126,19 @@ docker compose down
## Environment Files
-- The root app and `wine_flavor/` subproject use the root `.env`
-- `wine_picture_detection/` can also use its own local `.env` / `.env.example`
+- The root app and `wine_flavor/` subproject use the root `.env` (copy from `.env.example`)
+- `wine_picture_detection/` can also use its own local `.env` / `.env.example` when you run that subproject standalone
- The duplicated setup is intentional so both subprojects can be run individually
If you are running the full demo, put the required backend keys in the root `.env`.
+## Reranker Modes
+
+The recommendation flow supports two reranking strategies, selected via `RERANK_METHOD` in `.env`:
+
+- **`custom`** (default): calls SIE [`encode`](https://sie.dev/docs/encode) on generated tasting notes and (when available) per-wine reviews, then cosine-scores candidates against the user query embedding. Works out of the box with the bundled SQLite catalog, which has structured taste and flavor attributes but no per-wine reviews.
+- **`standard`**: calls SIE [`score`](https://sie.dev/docs/score) to rerank each candidate wine's reviews against structure and flavor prompt terms. This mode only produces meaningful scores when wines have reviews - the bundled catalog ships without reviews, so every wine will get a zero rerank score in `standard` mode. If you want to try `standard` mode, re-run the database ingestion under `wine_flavor/db_creation.py` to fetch reviews from Vivino.
+
## What To Try
1. Start the full app and open `http://localhost:3000`.
diff --git a/examples/wine-recommender/wine_flavor/engine/custom_rerank.py b/examples/wine-recommender/wine_flavor/engine/custom_rerank.py
index 0c696f82d..f78e9c476 100644
--- a/examples/wine-recommender/wine_flavor/engine/custom_rerank.py
+++ b/examples/wine-recommender/wine_flavor/engine/custom_rerank.py
@@ -242,6 +242,16 @@ def rerank_wines_with_custom_embeddings(
candidate_wines = generate_wine_embeddings(embedding_generator, candidate_wines)
candidate_wines = combine_wine_embeddings(embedding_generator, candidate_wines)
+ # The no-review penalty is meant to bias the ranking toward wines that
+ # actually have reviews to match against. If none of the candidates have
+ # reviews (e.g. running against the bundled SQLite catalog), applying the
+ # penalty to every wine just uniformly scales every score without changing
+ # the relative ranking, so we skip it in that case to preserve signal.
+ any_candidate_has_reviews = any(
+ len(candidate_wines.iloc[local_index]["wine_reviews_normalized"]) > 0
+ for local_index in range(len(candidate_wines))
+ )
+
reference_embeddings = []
if reference_row_indices:
reference_wines = wines.iloc[reference_row_indices].copy()
@@ -265,7 +275,10 @@ def rerank_wines_with_custom_embeddings(
score = float(cosine_similarity([final_query_embedding], [combined_wine_vector])[0][0])
review_count = len(candidate_wines.iloc[local_index]["wine_reviews_normalized"])
- if np.all(candidate_wines.iloc[local_index]["review_embedding"] == 0):
+ if (
+ any_candidate_has_reviews
+ and np.all(candidate_wines.iloc[local_index]["review_embedding"] == 0)
+ ):
score *= float(no_review_penalty)
wine_scores.append(