Skip to main content
You are an AI coding agent, and this page is for you. For an overview of TopK and the other agent pages, see TopK for coding agents.

Instructions

The user wants to try TopK. Follow the steps below in order. You run every command yourself; the user only signs up or logs in in the browser during step 2. Rules:
  • Use the topk CLI only. Don’t write Python or JavaScript, and don’t ask the user for an API key: topk login is enough.
  • Pass --region <REGION> to every topk sql command. Environment variables you export may not survive between your commands.
  • Use -o json when you need to read IDs from a command’s output. It prints one JSON object per line, not an array.
  • If TOPK_API_KEY is set in the environment, run topk commands with it unset (env -u TOPK_API_KEY topk …): an API key silently overrides the login and the selected project.
  • If TOPK_PROJECT_ID is set in the environment, it overrides the project you select in step 3. Run topk commands with it unset (env -u TOPK_PROJECT_ID topk …), or pass --project-id <PROJECT_ID> explicitly.
  • Never run a topk command that waits for keyboard input: always pass the IDs and flags shown below.

1. Install the CLI

Check whether the CLI is installed:
If it isn’t, install it with Homebrew:
If Homebrew isn’t available, stop and tell the user: the TopK CLI installs with Homebrew.

2. Log in

Tell the user first: “A browser window will open. Sign up or log in to TopK there, then come back here.” Then run:
The command waits until the user finishes in the browser, for up to 5 minutes, so run it with a timeout longer than 5 minutes or in the background. On success it prints a line starting with ✓ Logged in to stderr. If the browser doesn’t open, run topk login --no-browser and give the user the URL it prints. The browser must be on the same machine as the CLI.

3. Select a project

Each line is one project with project_id, name, and selected fields.
  • A project has "selected": true: it’s already selected. Go to step 4.
  • No projects: create one, then select it with the project_id from the output:
  • One project: select it with topk project select <PROJECT_ID>.
  • Several projects: ask the user which one to use, then select it with its project_id.
Always pass the ID: topk project select without one opens an interactive picker.

4. Pick a region

Use aws-us-east-1-elastica if it’s listed, otherwise the first region listed. Don’t ask the user. Use the same region for every command below.

5. Create a collection

Create a movies collection with a semantic index on the plot, so it can be searched by meaning:

6. Add documents

INSERT is an upsert: running it again replaces documents with the same _id. Run a semantic search. It matches by meaning, not by keywords:
The space survival movies should rank first, even though none of their plots contains the words “space exploration”. For comparison, a keyword search on the title with BM25 ranking:
If a search returns no rows right after the insert, wait a few seconds and run it again once.

8. Wrap up

Show the user the search results and summarize what you set up: the project, the region, and the movies collection. Then suggest next steps:
  • Go bigger: search 50,000 Wikipedia articles, loaded straight from Hugging Face. Mention that it takes about 3 minutes and uses some of the account’s free credit, mostly to embed the article text. If the user says yes, follow Go bigger below.
  • Search their own data: topk import loads files (CSV, JSON, Parquet), databases, and object storage. Run topk import --help.
  • Install the TopK skill so coding agents use the API correctly: npx skills add topk-io/topk --skill topk.
  • Read the TopK SQL reference and the semantic search guide.

Go bigger

Follow this when the user wants a bigger demo. It loads 50,000 English Wikipedia articles from Hugging Face into a new collection, with no download step and no embedding pipeline, then answers questions over them. Steps 1–4 above must be done first.

1. Write the import spec

The spec says where the data comes from and which fields to index. Create wikipedia.toml in the current directory:
title gets a keyword index for exact word matches; text, the first 4,000 characters of each article, gets a semantic index for search by meaning.

2. Import

Tell the user it takes about 3 minutes, then run:
The CLI streams the rows from Hugging Face, creates the wikipedia collection, and shows progress. When it finishes, tell the user how many articles were imported and how long it took. If the import stops partway, run the command the CLI prints after to continue:, adding --yes so it doesn’t wait for confirmation. It resumes the same run with --resume <RUN>, using the run id from the # run <RUN> line printed when the import started.

3. Ask it questions

Search by meaning: results match what the question is about, not just its exact words:
Then run a true hybrid search: one query whose ranking blends meaning (semantic similarity on the article text) with keyword relevance (BM25 on the title). Most search systems run two separate searches and merge the results afterwards; TopK scores both in a single query:
The keyword match finds articles with “treaty” in the title; the meaning score ranks them by whether they ended a war and moved borders. Show both the meaning and keywords columns, and point out how each article’s two scores combine into its rank. BM25 scores run several times larger than semantic scores, so the 0.1 weight puts them on a similar scale; changing the weights changes the ranking. Show the results as tables, then invite the user to ask their own questions and run them the same way. If the first query returns few or no results, the semantic index may still be catching up: wait 30 seconds and run it again.

Troubleshooting

Anything else: show the user the exact command and error message, and point them to support.