> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Addresses

> Points, selections, ranked selections, valid time, worlds and change logs: where every read and write acts.

An address says where a verb acts. It is a value built from a table, and no
address changes what a verb means.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
orders(key)                                      // a point, by key
customers({ email })                             // a point, by a unique field set
orders.where({ customer }).by("placed")          // a selection, in order
  .descending().first(20)                        // bounded: ctx.list reads all of it
docs.search("textBody", text).first(10)               // ranked, always bounded
orders(key).pick("state")                        // fewer fields
tariffs(sku).at(instant)                         // at a valid instant
orders.where({ customer }).in(version)           // in another world
orders.where({ customer }).changes               // the change log, as a selection
```

## Points

A point is one place: the fact of a table at a key, or at a unique field set.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const order = await ctx.get(orders(key));
const customer = await ctx.get(customers({ email: "ada@example.com" }));
const stocked = await ctx.has(stock({ warehouse: "lyon", sku }));
```

A minted key is passed alone. A declared key with one field is passed alone,
and one with several fields as an object. A unique field set is always an
object.

An application fact ID carries its issued relation and original allocation.
An admitted sealed archive copy keeps that ID, and the destination catalog
maps its relation to the local table. Keep IDs as opaque strings and use an
ID field for a reference that travels with the fact. The destination's
archive configuration must also map any renamed target relation named by
the ID field. A physical `Ref`
carries an address bound to one table incarnation.

## Selections

A selection is an ordered set of facts.

| Method | Meaning |
| - | - |
| `.where({ field: value })` | Facts whose field equals the value |
| `.where({ field: { from, to } })` | Facts whose field falls in the half-open range; `null` is unbounded |
| `.by(field)` | Order by the field, ascending |
| `.descending()` | Reverse the order |
| `.first(n)` | The first `n` facts in order: a **bounded** selection |
| `.atMost(n)` | Every fact, bounded: `ctx.list` returns them all, or refuses `Limit` when there are more than `n` |
| `.pick(...fields)` | Fewer fields, and a narrower read |

A selection ranges over at most one field. A declared index must serve every
selection; one no index serves is refused with the index to add (see
[Indexes](https://docs.bijection.com/database/indexes.md)).

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
// index: [["customer", "placed"]]
const week = orders.where({ customer, placed: { from: monday, to: nextMonday } });
const latest = orders.where({ customer }).by("placed").descending().first(20);
```

The table itself is the selection of every fact: `ctx.count(orders)`,
`ctx.page(orders, { size: 50, cursor })`, `orders.first(10)`,
`orders.atMost(500)`.

`.first(n)` truncates: it is the top `n`, and the facts past it are not read.
Use `.atMost(n)` when the code needs all of a set it expects to be small, so
that a set that grew past `n` refuses instead of being cut short. Walk a large
selection with `ctx.page`, and keep a sum or count over it as a declared
[`total`](https://docs.bijection.com/database/capabilities#totals).

On a [protected table](https://docs.bijection.com/database/protected-tables.md) (labelled, erasable or with
a `lifetime`), an index keeps only a token of its fields. A selection that
fixes every field of an index by equality takes every verb. Any other
selection over it, and a whole table with a declared key, is read only with
`ctx.list(selection.atMost(n))`: `.first(n)`, `ctx.page` and `ctx.count` of
it refuse `ProtectedShapeUnsupported`, unless its index declares a reviewed
[store exposure](https://docs.bijection.com/database/protected-tables.md#expose-an-order-to-the-store).

## Ranked selections

A ranked selection orders facts by relevance or distance, and is always
bounded by `.first(n)`. Each result is a hit: `{ fact, score }`.

| Address | Ranks by |
| - | - |
| `docs.search("textBody", text).first(n)` | Text relevance on a `t.text()` field |
| `docs.near("embedding", vector).first(n)` | Vector distance on a `t.vector(n)` field |
| `docs.where({ owner }).near("embedding", vector).first(n)` | Vector distance among facts matching the where fields |
| `docs.where({ owner: { oneOf: [a, b] } }).near("embedding", vector).first(n)` | Vector distance among facts whose field holds one of the values |
| `docs.search("textBody", text).near("embedding", vector).first(n)` | Both rankings fused by reciprocal rank; each hit adds `rank: { text, vector }` |
| `sites.where({ region }).near("site", origin, { distance }).first(n)` | Metres from an origin, on an indexed `t.geometry` field |
| `sites.where({ region }).region("site", area, { relation, distance }).first(n)` | Facts whose geometry relates to an area (`intersects` by default); these are facts, not hits |

A `where` before `.near` filters the ranking, and needs an index that lists
the where fields followed by the ranked field.

## Valid time

Series and timelines have valid time.

| Address | Meaning |
| - | - |
| `tariffs(sku)` | The fact in force at the frame's `at` (by default, now) |
| `tariffs(sku).at(instant)` | The fact in force at that instant |
| `tariffs(sku).over({ from, to })` | The facts over a valid interval, each with its `from` and `to` |
| `readings(meter).over({ from, to })` | The samples in the interval, each with its `at` |

A plain table has no valid time: `.at` and `.over` on its points are type
errors. See [Series and timelines](https://docs.bijection.com/database/series-and-timelines.md).

## Worlds

`.in(world)` reads a point or selection in another world: a version or a
branch. Without it, an address is in the frame's world, normally the head.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const before = await ctx.get(orders(key).in(version));
const proposed = await ctx.list(orders.where({ customer }).in(branch).first(20));
```

A version stays readable for the table's `history`, or while a pin holds it.
See [History and lifetime](https://docs.bijection.com/database/history-and-lifetime.md).

## Change logs

`.changes` is the change log of a table, a selection or a point, as a
selection. Each change is `{ key, before, after, version }`: the fact before
and after it (either `null`), and the version that committed it.
`.since(version)` keeps the changes after a version.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const recent = await ctx.list(orders(key).changes.descending().first(10));
const walk = orders.changes;
const page = await ctx.page(savedCursor === null ? walk : walk.since(savedCursor), { size: 100 });
```

Finish a baseline or descending scan using the page's `next`
continuation. Save `page.cursor` in a `t.changeCursor` field to continue
the same structural feed with `.changes.since(cursor)`. The cursor carries
delivery across closures. An admitting frame receives `erased` or
`expired`. Other frames receive `removed` only for facts delivered to that
cursor's chain. Drop the id from the local copy for any of these changes.
Starting from a plain version begins a fresh chain. A structural feed whose
delivery inventory reaches its bound returns a null cursor.

A change log is also a reaction's source: `mutation({ on: orders.changes }, …)`
runs once per change. See [Functions](https://docs.bijection.com/functions).

## Presence history

`orders(key).presence` is a minted fact's presence history: each committed
version, its instant, and the valid periods the fact was present in. It is
bounded by `.first(n)`, at most 64, and takes a half-open version range.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const versions = await ctx.list(
  orders(key).presence.where({ version: { from: v1, to: null } }).descending().first(10),
);
```

Each entry is `{ version, at, proposed, timeline }`, where `timeline` lists
`{ from, to, present }`.

## A family member's partition

On a [family table](https://docs.bijection.com/database/family-tables.md), every address is at the frame's
member. `table.of(family.of(key))` addresses another member's partition.

## A task

A `Task` identifies a single `sys.tasks/<id>` point. `ctx.get(task)` reads its
state, or returns `null` when the task is absent. See
[Effects](https://docs.bijection.com/functions/effects.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.