API=https://app.truvec.dev
TOKEN=$(curl -s -X POST $API/api/auth/login -d "username=you@example.com" -d "password=a-strong-password" | jq -r .access_token)
AUTH="Authorization: Bearer $TOKEN"
# 1. Create a project
PROJECT=$(curl -s -X POST $API/api/v1/projects -H "$AUTH" -H "Content-Type: application/json" \
-d '{"name": "Support assistant"}' | jq .id)
# 2. Upload a document with the default chunking
curl -s -X POST "$API/api/v1/documents/upload?project_id=$PROJECT" -H "$AUTH" \
-F "file=@help-center.pdf" -F "chunking_strategy=recursive" -F "chunk_size=1000" -F "chunk_overlap=200" > /dev/null
# 3. Generate a golden dataset, then commit it (review it in the interface first!)
DATASET=$(curl -s -X POST $API/api/v1/golden-datasets -H "$AUTH" -H "Content-Type: application/json" \
-d "{\"project_id\": $PROJECT, \"name\": \"Generated v1\", \"number_of_questions\": 30}" | jq .id)
curl -s -X POST $API/api/v1/golden-datasets/$DATASET/commit -H "$AUTH" > /dev/null
# 4. Compare two models (ids from GET /api/v1/embedding-models)
BENCHMARK=$(curl -s -X POST $API/api/v1/benchmarks -H "$AUTH" -H "Content-Type: application/json" \
-d "{\"project_id\": $PROJECT, \"golden_dataset_id\": $DATASET, \"name\": \"small vs large\", \"model_ids\": [1, 2], \"top_k\": 5}" | jq .id)
# 5. Wait for the comparison to finish
until [ "$(curl -s $API/api/v1/benchmarks/$BENCHMARK -H "$AUTH" | jq -r .status)" != "running" ] && \
[ "$(curl -s $API/api/v1/benchmarks/$BENCHMARK -H "$AUTH" | jq -r .status)" != "pending" ]; do sleep 5; done
# 6. Print the ranking
curl -s $API/api/v1/benchmarks/$BENCHMARK -H "$AUTH" \
| jq '.results.comparison[] | {model: .model_name, mrr, recall, cost_per_1k_queries: .cost.cost_per_1k_queries_usd}'