Search & Retrieval

Build a Document Search Index with a Serverless Job

Search 1,000 Wikipedia passages by meaning with Qwen embeddings. The Serverless Job runs on a preemptible VM and saves each result to Object Storage, so a rerun skips the passages you’ve already indexed.

Build it with an agent

Paste into Claude Code, Cursor, or any coding agent — it builds the recipe for you.

Build the searchable index of 1,000 Dolly passages using the pinned recipe at
https://github.com/nebius/serverless-ai-cookbook/tree/da7bb2d388c0b589af85a35a08d39aec9746c4be/inference/document-search

Check out da7bb2d388c0b589af85a35a08d39aec9746c4be, enter inference/document-search, read the README, prepare the test data with `python3 scripts/prepare_job_data.py`, then run `python3 -m unittest discover -s tests`. Use the Nebius Jobs and data/secrets skills if installed.

Use my existing Nebius AI Cloud project and its region, internet-enabled subnet and private bucket. Confirm the region offers Serverless AI. Set NEBIUS_REGION to the bucket’s region. Set GPU_PLATFORM and GPU_PRESET together from the project’s available one-GPU configurations. Check preemptible eligibility and compatibility with the recipe’s PyTorch image for that platform. The launcher follows the spot price without a GPU-hour cap. Check the selected GPU’s current rate against my budget. If I require a hard hourly cap, stop before submitting and explain why. Find the S3 secret before asking me for its ID:

1. Check S3_SECRET_ID in the recipe configuration. If it’s missing or stale, find a successful document-index Job in the same project that used this bucket. Read only the two bindings named AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and their mysterybox_secret.secret_id references, without printing other environment values. They should point to the same mbsec-… ID.
2. Verify that secret and its primary version are active. For discovery, use `nebius mysterybox secret list --parent-id "$NEBIUS_PROJECT_ID" --all --show-scheduled-for-deletion`. Use secret and version metadata only. Names alone cannot identify the right credentials. Never fetch the payload, dump a Job’s environment, or ask me for key values.
3. Reuse a confirmed active match. If the matching secret or version is scheduled for deletion, identify it and ask whether to restore it or use another. Restore only the item I approve and recheck its state. If several candidates fit, ask once which reference to use. If access to a known ID is denied, explain which metadata you couldn’t read and ask for read access or another usable reference. For a first run with no suitable secret, guide me through entering both named keys in Cryptography → SecretStash → Create secret. I share only the mbsec-… ID.

Put only the secret reference in S3_SECRET_ID. Keep the S3 key values in SecretStash. Set RECIPE_REF to the checked-out commit. Choose a fresh RUN_ROOT with one writer. Carry forward any approved scope and GPU budget. Ask for a specific limit if one is missing.

Run `JOB_NAME=document-index bash scripts/submit.sh --dry-run`, then run `JOB_NAME=document-index bash scripts/submit.sh --async` once authorized. Require Completed, “1,000 new, 0 reused, 0 remaining”, 1,970 chunks and a first-ranked Dolly passage answering “What is stalemate in chess?”. Report the counts, report location and any failures. Preserve the index and shared resources.

For my own question, keep the same bucket region and completed prefix. Use a new Job name and `--env 'SEARCH_QUERY=…'`. Save the previous report first if requested. Only test recovery if I ask. Use a separate prefix, limit the first Job to 600 documents, then verify that the second Job reuses 600 documents and finishes the remaining 400.

Recipe

Let’s turn 1,000 Wikipedia reference passages from the Databricks Dolly dataset into something you can search by meaning. Qwen3-Embedding-0.6B creates the embeddings, and one Nebius Serverless Job builds the index and saves a search report to Object Storage. A preemptible GPU can cost less than an on-demand GPU. If Nebius reclaims it, the next Job reuses the documents already in your bucket.

Source code

On November 19, 2026, our preemptible H100 Job indexed all 1,000 passages with Qwen/Qwen3-Embedding-0.6B and returned the search report in about six minutes, excluding account and storage setup. Here’s the first result for “What is stalemate in chess?”

Stalemate is a situation in chess where the player whose turn it is to move is not in check and has no legal move. Stalemate results in a draw.

Read the passage in the Dolly dataset viewer.

1. Set up

To run this cookbook, you need a Nebius AI Cloud account and access to a project where you can run paid GPU workloads. Use your project’s region if it offers Serverless AI and a compatible preemptible GPU. Check regional availability.

On your computer, install Git and the Nebius CLI 0.12.305 or newer, then get the recipe:

git clone https://github.com/nebius/serverless-ai-cookbook.git
cd serverless-ai-cookbook
git checkout --detach da7bb2d388c0b589af85a35a08d39aec9746c4be
cd inference/document-search

Use your existing CLI profile for that project (nebius profile activate PROFILE_NAME to switch). If this is your first sign-in, run nebius profile create and select the project.

In the console, open the same project. You need four things:

  • A private bucket in the project’s region, under Object Storage → Buckets. The Job uses this region to connect to the bucket.

  • An S3 access key for a service account with storage.object-editor access to that bucket. Create the key under the account’s Access keys and keep its ID and secret private.

  • One active SecretStash secret for this bucket with two text entries, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Reuse the secret from a previous document-index Job if it’s still active. For a first run, open Cryptography → SecretStash → Create secret and use Add pair for the second entry. Copy the secret’s mbsec-… ID.

  • Your project-… and vpcsubnet-… IDs. Copy the project ID from the project selector’s ⋯ menu → Copy project ID. Find the subnet under Networking → Virtual Networks → Subnets; choose an internet-enabled one.

Your account needs permission to create Jobs and read the secret payload (mysterybox.payload-viewer, included in admin).

Run nebius compute platform list --parent-id YOUR_PROJECT_ID with your project ID. Choose a platform marked allowed_for_preemptibles: true and one of its single-GPU presets. GPU platforms and presets.

GPU GPU_PLATFORM GPU_PRESET
H100 gpu-h100-sxm 1gpu-16vcpu-200gb
L40S (AMD) gpu-l40s-d 1gpu-16vcpu-96gb
H200 gpu-h200-sxm 1gpu-16vcpu-200gb

We ran the Job live on L40S and H100 GPUs in eu-north1. For selected configurations in other regions, offline tests checked the launch arguments only.

Fill in your region, GPU settings and resource IDs. Choose a bucket prefix you haven’t used before. Your S3 keys stay in SecretStash.

cat > .env <<'ENV'
export NEBIUS_PROJECT_ID="YOUR_PROJECT_ID"
export NEBIUS_SUBNET_ID="YOUR_SUBNET_ID"
export NEBIUS_REGION="YOUR_BUCKET_REGION"
export GPU_PLATFORM="YOUR_GPU_PLATFORM"
export GPU_PRESET="YOUR_ONE_GPU_PRESET"
export S3_SECRET_ID="YOUR_SECRET_ID"
export RUN_ROOT="s3://YOUR_BUCKET/document-index-demo-01"
export RECIPE_REF="$(git rev-parse HEAD)"
ENV
source .env

The Job fetches its code from GitHub at RECIPE_REF, matching your checkout. If you change the worker code, push the commit first; the Job only sees what is on GitHub. For a fork, update the repository URL in scripts/run_job.py.

The Job uses one preemptible GPU, an 80 GiB temporary disk and a one-hour timeout. Check the price for your region and GPU before submitting. Compute is billed while the image and model load. Current prices.

The Job prepares the same dataset version for you each time. These are reference passages, not full articles; their provenance and CC BY-SA 3.0 license are included.

2. Index all 1,000 documents

The commands below follow the current spot price with no GPU-hour price cap. For our November 19, 2026 run, L40S capacity was unavailable in the test project, so we used an H100 with a separate $2.50/GPU-hour cap.

The first command checks your settings. The second submits the Job.

JOB_NAME=document-index bash scripts/submit.sh --dry-run &&
JOB_NAME=document-index bash scripts/submit.sh --async

Open Serverless AI → Jobs → document-index → Logs to follow along. The first few minutes can be quiet: in our November 13, 2026 tests with Qwen3-Embedding-0.6B, provisioning and pulling the image took roughly five minutes before Running.

Once it reaches Completed, look for:

Finished: 1,000 new, 0 reused, 0 remaining.

That’s 1,000 documents / 1,970 chunks ready to search. The Job has already saved a first search result for you.

3. Search the index

The Job runs this question automatically:

What is stalemate in chess?

In Logs, the first passage should explain when the game is a draw. Follow its link to read it in the dataset viewer.

To read the results in your browser, open Object Storage → your bucket → document-index-demo-01 → outputs. Download search.html and open it on your computer. search.json contains the ranked passages, and the other JSON files hold counts and timings. Your bucket stays private.

To ask your own question, start a second billed Job on the same RUN_ROOT after the first one finishes. It reuses all 1,000 saved documents and embeds only your question. Download the current report first if you want to keep it. The new results replace outputs/search.html and outputs/search.json.

JOB_NAME=document-search-question bash scripts/submit.sh --async \
  --env 'SEARCH_QUERY=How does a game of chess end in a draw?'

Use a new Job name for each question. Check its logs for 0 new, 1,000 reused, 0 remaining and the ranked passages.

If you’re finished, skip to step 4 to clean up. Keep the index prefix, .env and SecretStash secret if you want to ask more questions or try recovering a Job.

What if the Job is interrupted?

Each finished document is saved to Object Storage as its own object. If the Job stops, those embeddings stay in your bucket. Submit a new Job with the same input, settings and prefix, and it’ll skip what’s already saved and finish the rest. The recipe refuses to mix different data or model settings in the same prefix.

Nebius has an on-failure restart policy, which restarts a container that fails inside a running Job. It doesn’t cover preemption, missing capacity at startup, unexpected VM stops, or failures and timeouts during startup. We use --restart-policy never here so you can inspect what happened and decide when to resubmit. Automatic job restarts.

  • Wait for the previous attempt to show Completed, Failed, Cancelled or Error.

  • Give the new Job a new name. Keep the original bucket region (NEBIUS_REGION), RUN_ROOT, RECIPE_REF, input and model settings.

  • Check the log’s reused and remaining counts. An unfinished document is recomputed.

  • Use one active Job per prefix. If you change the input or model settings, use a new prefix.

Try it yourself

Use a new test prefix and limit the first Job to 600 documents:

JOB_NAME=document-index-600 RUN_ROOT="$RUN_ROOT/optional-resume" \
  MAX_NEW_DOCUMENTS=600 bash scripts/submit.sh --async

Wait for Completed, then check the log for 600 new, 0 reused, 400 remaining. Now submit the second Job against the same test prefix, with no document limit:

JOB_NAME=document-index-resume RUN_ROOT="$RUN_ROOT/optional-resume" \
  bash scripts/submit.sh --async

Look for “600 documents already saved, 400 to go.” It should finish with 400 new, 600 reused, 0 remaining and 1,000 documents / 1,970 chunks. Here the Job stops on purpose; this is not a real preemption. Check that both test Jobs show Completed.

See the run records.

4. Clean up

Once a Job shows Completed, its compute has been released. Your index and reports stay in Object Storage. To stop an unfinished attempt, use Serverless AI → Jobs → ⋯ → Cancel.

Before deleting resources, check that every Job using them shows Completed, Failed, Cancelled or Error. When you’re finished, delete the prefixes and SecretStash secret you created for this recipe. If you created a dedicated S3 key, delete it under the service account’s Access keys. Keep any keys and buckets you share with other workloads.