---
title: "Airbnb listing search demo: Jev in a spreadsheet formula"
type: guide
tags: [demo, google-sheets, shortlist, choice, score, ranking]
created: 2026-11-07
updated: 2026-11-07
confidence: high
sources:
  - raw/docs/demos__airbnb-listing-search.md
  - raw/docs/demos.md
  - raw/docs/primitives__choice.md
  - raw/docs/primitives__score.md
  - raw/docs/api.md
  - raw/docs/models.md
  - raw/docs/model-jaggedness.md
jev_version: "jev-1.14.0"
summary: "TypeSafe's Google Sheets demo: =JEV_TOP10 ranks 1,000 Cape Town listings against a plain-English request in 11 Jev requests (10 Choice shortlists, 1 Score batch)."
---

# Airbnb listing search demo: Jev in a spreadsheet formula

> **TL;DR** TypeSafe's demo (first in the docs' 2026-11-07 capture) is a Google Sheets custom function, `=JEV_TOP10(B1, Listings!A2:H1001)`, that returns the 10 best of 1,000 Cape Town listings for a plain-English request, each with a mark out of 10. It works in two stages: 10 parallel Choice requests over 100 listing IDs each keep the top 5 per group, then one request with 50 Score questions ranks the shortlist. That is 11 requests instead of 1,000, and TypeSafe says the search finishes "in about a second". The full Apps Script is published and copied below verbatim.

## What it shows

- **Problem.** Filters handle price, bedrooms and guests. They cannot handle "allows dogs", "walk to the beach" or "has backup power for load-shedding", which live in free-text descriptions.
- **Why one request per listing fails.** One Score request per listing works, but TypeSafe says 1,000 of them in sequence take more than 30 seconds. Google Sheets stops a custom formula at 30 seconds.
- **The fix: shortlist, then score.** One request can hold many listings. A Choice over 100 listing IDs returns a probability for each, so one request ranks a whole group. The API allows a maximum of 255 options per Choice (raw/docs/api.md).

| Stage | Requests | Question | What code does with the answer |
|---|---|---|---|
| Shortlist | 10, in parallel | Choice `best` over 100 IDs (`L0`…`L999`, `criteria` values `null`), each listing's line carrying the first 300 characters of its description | Keeps the 5 IDs with the highest probability per group: 50 in all |
| Score | 1 | One Score question per shortlisted listing, keyed by its ID, full description up to 1,500 characters, five levels | Converts each `score` (0–4) to a mark out of 10, returns the top 10 |

The five levels run from "Not a match at all" to "Matches everything asked for". TypeSafe's example: for "6 people and a dog on the beach", the top result scores 8.8. Its description says it sleeps 10, is minutes from the beach and is pet-friendly. The docs give no model version or run date for that example. The script sends `jev-latest`, which resolves to `jev-1.14.0` as of the 2026-11-07 docs capture ([[reference/models-and-pricing]]).

## Step 1: copy the sheet and get a key

1. Copy the sheet: https://docs.google.com/spreadsheets/d/1E1UOTwk2QIA9ZxIieXPvvQaGPOCZn7991bT49S07bRA/copy. It holds the 1,000 listings and the `JEV_TOP10` formula.
2. Create a TypeSafe key at https://console.typesafe.ai/keys.
3. In the copy: **Extensions > Apps Script > Project Settings > Script properties**, add `TYPESAFE_API_KEY` with your key. The script comment says there is "No permission prompt."

## Step 2: lay out the data

`Listings!A2:H1001` must have these eight columns in this order: Name, Type, Price per night (R), Bedrooms, Guests, Rating, Description, Link. Rows with an empty Name are dropped.

The data is a random sample of 1,000 listings from Inside Airbnb's 23 September 2026 scrape of Cape Town (https://insideairbnb.com/get-the-data/, CC BY 4.0). TypeSafe kept listings that have a price and a description of at least 200 characters. It removed HTML line breaks and repeated whitespace, and flattened amenities to a comma-separated list.

## Step 3: the Apps Script (verbatim)

Paste this as `Code.gs` if you are building it from scratch. The copied sheet already contains it.

```javascript
/**
 * JEV_TOP10: find the 10 listings that best match a plain-language request, using TypeSafe Jev.
 *
 * Setup: Extensions > Apps Script, paste this file, save. Then Project Settings >
 * Script properties: add TYPESAFE_API_KEY with your TypeSafe key. No permission prompt.
 *
 * Usage: =JEV_TOP10(B1, Listings!A2:H1001)
 *   The listing columns must be: Name, Type, Price per night (R), Bedrooms, Guests, Rating,
 *   Description, Link.
 *
 * How it works, in 11 requests instead of one per listing:
 *   1. Shortlist: the listings are split into groups of 100. One request per group, all in
 *      parallel, asks a Choice question over the group's listing IDs. Jev returns a
 *      probability for every listing, and the 5 most likely go through.
 *   2. Score: one request holds the shortlisted listings in full, with one Score question
 *      per listing. The 10 best scores are returned, from 0 to 10.
 * Results are cached for six hours per request.
 */

const GROUP_SIZE = 100;
const SHORTLIST_PER_GROUP = 5;
const TOP = 10;
const SHORT_DESCRIPTION = 300;
const FULL_DESCRIPTION = 1500;
const LEVELS = [
  'Not a match at all',
  'Matches little of what was asked for',
  'Matches some of what was asked for',
  'Matches most of what was asked for',
  'Matches everything asked for',
];

/**
 * Returns the 10 listings that best match a request, with a 0-10 match score.
 *
 * @param {string} request What you're looking for, in plain language.
 * @param {Listings!A2:H1001} listings Name, Type, Price, Bedrooms, Guests, Rating, Description, Link.
 * @return Match, Name, Type, Price, Bedrooms, Guests, Rating, Link for the top 10.
 * @customfunction
 */
function JEV_TOP10(request, listings) {
  const key = PropertiesService.getScriptProperties().getProperty('TYPESAFE_API_KEY');
  if (!key) throw new Error('Add TYPESAFE_API_KEY under Project Settings > Script properties.');
  request = String(request || '').trim();
  if (!request) return [['Type what you are looking for in B1.']];

  const rows = listings.filter((r) => r[0] !== '');
  const cache = CacheService.getScriptCache();
  const cacheKey = digest(`${request}\n${rows.length}\n${rows.map((r) => r[7]).join('|')}`);
  const hit = cache.get(cacheKey);
  if (hit) return JSON.parse(hit);

  // Stage 1: one Choice over each group of 100 listing IDs, all groups in parallel.
  const groups = [];
  for (let start = 0; start < rows.length; start += GROUP_SIZE) {
    groups.push(rows.slice(start, start + GROUP_SIZE).map((_, j) => start + j));
  }
  const shortlistResponses = UrlFetchApp.fetchAll(groups.map((ids) => jevRequest(key, {
    state: ids.map((i) => line(i, rows[i], SHORT_DESCRIPTION)).join('\n'),
    questions: {
      best: {
        type: 'choice',
        instructions: `Which listing best matches what the guest is looking for: ${request}`,
        criteria: Object.fromEntries(ids.map((i) => [`L${i}`, null])),
      },
    },
  })));
  const shortlist = shortlistResponses.flatMap((res) => {
    const p = parse(res).answers.best.probabilities;
    return Object.keys(p).sort((a, b) => p[b] - p[a]).slice(0, SHORTLIST_PER_GROUP).map((id) => Number(id.slice(1)));
  });

  // Stage 2: score every shortlisted listing in one request.
  const scored = parse(UrlFetchApp.fetchAll([jevRequest(key, {
    state: shortlist.map((i) => line(i, rows[i], FULL_DESCRIPTION)).join('\n\n'),
    questions: Object.fromEntries(shortlist.map((i) => [`L${i}`, {
      type: 'score',
      instructions: `How well does listing [L${i}] match what the guest is looking for: ${request}`,
      criteria: LEVELS,
    }])),
  })])[0]).answers;

  const top = shortlist
    .map((i) => ({i, score: Math.round((scored[`L${i}`].score / (LEVELS.length - 1)) * 100) / 10}))
    .sort((a, b) => b.score - a.score)
    .slice(0, TOP)
    .map(({i, score}) => {
      const [name, type, price, beds, guests, rating, , link] = rows[i];
      return [score, name, type, price, beds, guests, rating, link];
    });
  cache.put(cacheKey, JSON.stringify(top), 6 * 60 * 60);
  return top;
}

function line(i, r, descriptionChars) {
  const [name, type, price, beds, guests, , description] = r;
  return `[L${i}] ${name} | ${type} | R${price}/night | ${beds || '?'} bedrooms | sleeps ${guests} | ${String(description).slice(0, descriptionChars)}`;
}

function jevRequest(key, body) {
  return {
    url: 'https://api.typesafe.ai/v1/systemone',
    method: 'post',
    contentType: 'application/json',
    headers: {Authorization: `Bearer ${key}`},
    muteHttpExceptions: true,
    payload: JSON.stringify(Object.assign({model: 'jev-latest'}, body)),
  };
}

function parse(res) {
  if (res.getResponseCode() !== 200) {
    throw new Error(`Jev returned HTTP ${res.getResponseCode()}: ${res.getContentText().slice(0, 200)}`);
  }
  return JSON.parse(res.getContentText());
}

function digest(text) {
  return Utilities.base64EncodeWebSafe(Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, text));
}
```

How the code reads the answers:

- **Shortlist.** `answers.best.probabilities` is the per-option map of a Choice answer ([[concepts/choice]]). The code sorts its keys by probability and keeps the first 5. It never reads `choice` or `confidence`.
- **Score.** `answers.L<i>.score` is the position on the 0–4 level line ([[concepts/score]]). The mark is `round(score / 4 × 100) / 10`, so 0–10 with one decimal.
- **Errors.** `muteHttpExceptions: true` plus `parse()` turns any non-200 into a cell error showing the status and the first 200 characters of the body. There is no retry ([[reference/rate-limits-and-errors]]).
- **Caching.** The cache key is a SHA-256 of the request text, the row count and every Link. Hits are served for 6 hours (`6 * 60 * 60` seconds), so editing other cells does not re-run the search.

## Step 4: search

Type a request in `B1`, for example "6 people and a dog on the beach". A new request in `B1` is a new search. The formula fills ten rows: Match, Name, Type, Price, Bedrooms, Guests, Rating, Link.

## Adapting it

- **Any "rank N free-text items against a query" sheet** fits this shape: products, CVs, support articles (inferred). Keep the ID-as-option trick and the two description lengths.
- **Group size** is bounded by the 255-option Choice limit and the 64k per-request / 32k per-question context ([[reference/models-and-pricing]]). Stage 2's state holds 50 descriptions of up to 1,500 characters each, so check it against those limits if you raise `SHORTLIST_PER_GROUP` or `FULL_DESCRIPTION`.
- **Keep it under 30 seconds.** Every Jev call goes through `UrlFetchApp.fetchAll`, so the two stages cost two round trips. A third sequential stage adds one more.
- **Pin the model** if a ranking must not change when the alias moves: replace `'jev-latest'` with `'jev-1.14.0'` ([[guides/production-operations]]).

## Gotchas

- **Shortlist recall is the ceiling.** A listing that misses its group's top 5 is never scored. Stage 1 sees only 300 characters of each description, so a detail further down ("backup power" at the end) can drop a good listing (inferred from the code).
- **Option order.** The docs' jaggedness list notes that Jev can lean toward the first Choice option. Shuffle the IDs and check the shortlist is stable ([[concepts/jaggedness-jev-1-13]], mode 8).
- **Numbers are text to Jev.** Prices go in as `R1234/night`. A request like "under R2000" asks Jev to compare numbers, which is a known weak spot. Filter price, bedrooms and guests in code first, and leave Jev the reading judgments ([[concepts/jaggedness-jev-1-13]]).
- **Large state.** Each shortlist request carries 100 listings, and most are irrelevant to any one request, which is another failure mode on the same list. Measure recall on your own data before trusting the cut.
- **Key in Script properties.** Treat the copied sheet as holding a live key: whoever can edit its Apps Script project can read the property (inferred). Do not share an editable copy with your key in it.

## Related

- [[concepts/choice]] — probabilities over many options
- [[concepts/score]] — levels, `score` position
- [[patterns/fan-out]] — many questions in one request (stage 2)
- [[patterns/noul-screen]] — another cheap-first-stage design
- [[cookbooks/rerank]] — the cookbook version of shortlist-then-rerank
- [[guides/smart-home-demo]] — the other "Made with Jev" demo
- [[reference/http-api]] — the request this script builds by hand

## Sources

- raw/docs/demos__airbnb-listing-search.md (https://docs.typesafe.ai/demos/airbnb-listing-search), captured 2026-11-07
- raw/docs/demos.md (https://docs.typesafe.ai/demos): the "Made with Jev" index card
- raw/docs/api.md (https://docs.typesafe.ai/api): 255 options per Choice
- raw/docs/primitives__choice.md, raw/docs/primitives__score.md: answer fields
- raw/docs/models.md (https://docs.typesafe.ai/models): context limits, aliases
- raw/docs/model-jaggedness.md (https://docs.typesafe.ai/model-jaggedness): option order, numbers, large state
