# sky.rl: the night sky as a graph

A single-file [Relate](https://relatedb.ai) graph database (Relate 1.3.0, openCypher). It holds every naked-eye star, every confirmed exoplanet and its host star, the 88 constellations with their stick figures, and links between nearby stars. Built by the pipeline at https://github.com/dhodapkarsoham/sky-graph. Counts and answers below come from a build on 2026-11-25. The star catalog and constellation lines are pinned, but planets come live from the NASA Exoplanet Archive, so a later build has slightly more planets.

Read this before you write a query. Facts below were checked against the file with `get_schema` (sample size -1) and direct queries.

## Build it

Needs the Relate CLI 1.3.0 and Python 3.9+.

```sh
git clone https://github.com/dhodapkarsoham/sky-graph.git
cd sky-graph
./run.sh          # fetch -> prepare -> build -> verify; writes ./sky.rl
```

## Serve it to an agent

```sh
relate serve --database /absolute/path/to/sky.rl --mcp stdio --read-only
```

The MCP server exposes two tools: `get_schema` and `read_cypher` (one read-only statement, with optional `parameters`). Writes are rejected.

## Node labels

**Star** (16,846). Naked-eye stars (V ≤ 6.5) from HYG v4.4, every exoplanet host, and every HYG star within 100 ly of the Sun.

| Property | Type | Meaning |
| --- | --- | --- |
| `id` | string, unique | `hyg-<n>` for HYG stars, `nasa-<host-slug>` for hosts not matched to HYG |
| `name` | string, indexed | Display name: proper name, else Bayer/Flamsteed, else a catalog id. The Sun is `"Sun"` |
| `ra_deg`, `dec_deg` | float, degrees | Right ascension and declination (J2000) |
| `mag` | float | Apparent visual magnitude (smaller is brighter) |
| `absmag` | float | Absolute magnitude (HYG stars only) |
| `dist_ly` | float, light-years | Distance from the Sun |
| `x_ly`, `y_ly`, `z_ly` | float, light-years | Heliocentric equatorial Cartesian position |
| `spect` | string | Spectral type, for example `G2V` |
| `ci` | float | B−V colour index (HYG only) |
| `lum` | float, solar luminosities | Luminosity (HYG only) |
| `naked_eye` | boolean, indexed | `mag ≤ 6.5`. False for the Sun |
| `neighborhood` | boolean | Within 100 ly of the Sun (the stars that have NEAR links) |
| `is_host` | boolean | Has at least one confirmed planet |
| `planet_count` | integer | Number of confirmed planets |
| `con` | string | IAU constellation abbreviation, for example `Cyg` |
| `host_name` | string | Host name as the NASA Exoplanet Archive spells it |
| `proper`, `bayer`, `flam`, `gl`, `hip`, `hd`, `hr`, `gaia_dr3`, `hyg_id` | mixed | Catalog names and numbers, where known |
| `source` | string | `"HYG v4.4"` or `"NASA Exoplanet Archive"` |

**Planet** (6,473). NASA Exoplanet Archive confirmed planets (PSCompPars).

| Property | Type | Meaning |
| --- | --- | --- |
| `name` | string, unique | For example `"TRAPPIST-1 e"` |
| `host_name` | string | Host star name (NASA spelling) |
| `radius_earth` | float, Earth radii | |
| `mass_earth` | float, Earth masses | Mass or M·sin i |
| `period_days` | float, days | Orbital period |
| `sma_au` | float, AU | Semi-major axis |
| `eq_temp_k` | float, kelvin | Equilibrium temperature |
| `insolation` | float, Earth = 1 | Stellar flux received |
| `disc_year`, `disc_decade` | integer | Discovery year (1992–2026) and decade (1990, 2000, …). `disc_decade` is indexed |
| `method`, `facility`, `facility_locale` | string | Same values as the linked Method and Mission nodes |
| `features` | list of 5 floats | Vector for similarity search (6,145 planets have one). See below |
| `features_imputed` | list of strings | Which of radius/mass were estimated from the other (Chen & Kipping 2017), if any |

**Constellation** (88): `abbr` (unique, for example `"Cyg"`), `name` (`"Cygnus"`), `genitive` (`"Cygni"`), `rank` (d3-celestial label rank, 1 = most prominent). Serpens is one constellation.

**Mission** (73): `name` (unique, the discovery facility, for example `"Kepler"`), `locale` (`"Space"`, `"Ground"` or `"Multiple Locales"`).

**Method** (11): `name` (unique): Astrometry, Disk Kinematics, Eclipse Timing Variations, Imaging, Microlensing, Orbital Brightness Modulation, Pulsar Timing, Pulsation Timing Variations, Radial Velocity, Transit, Transit Timing Variations.

## Relationship types

| Pattern | Count | Notes |
| --- | --- | --- |
| `(:Planet)-[:ORBITS]->(:Star)` | 6,473 | |
| `(:Planet)-[:FOUND_BY]->(:Mission)` | 6,473 | |
| `(:Planet)-[:DETECTED_VIA]->(:Method)` | 6,473 | |
| `(:Star)-[:IN]->(:Constellation)` | 16,845 | Every star except the Sun |
| `(:Star)-[:LINE_TO {con}]->(:Star)` | 743 | Constellation stick-figure segment between naked-eye stars. `con` is the constellation abbreviation |
| `(:Star)-[:NEAR {ly}]->(:Star)` | 11,688 | Between stars within 100 ly of the Sun that are at most 10 ly apart. `ly` is the 3D distance in light-years. **Stored once per pair: always match it undirected, `-[:NEAR]-`** |

## The `features` vector

Five numbers in this order: log10 radius, log10 mass, log10 period, equilibrium temperature, log10 insolation. Each is min-max scaled to [0, 1] using the 1st and 99th percentile across all planets, then clipped. Earth's vector is:

```
[0.088195, 0.095262, 0.53436, 0.09427, 0.416004]
```

Compare with `vector.similarity.euclidean(p.features, $earth)` (1 is identical; it equals 1 / (1 + d²)). A vector index named `planet_features` exists, but the brute-force function is fast at this size.

## Things to know before you query

- Match NEAR undirected. A directed `-[:NEAR]->` silently misses half the links.
- Relate 1.3.0 evaluates a per-hop filter in `SHORTEST` by enumerating paths, so it slows down exponentially with route length. With jumps of 6 ly or less there is no route from the Sun to TRAPPIST-1 and the query returns nothing at once. A route does exist from about 8.2 ly up, but it is 19 jumps long and `SHORTEST ... WHERE r.ly <= 8.5` does not finish. `relate serve` has no statement timeout, so such a query blocks the server until you restart it. For long routes, fetch the edges (`MATCH (a:Star)-[r:NEAR]->(b:Star) WHERE r.ly <= 8.5 RETURN a.id, b.id, r.ly`) and run Dijkstra yourself.
- Only HYG stars have `absmag`, `ci` and `lum`. Planets may lack radius, mass, period, temperature or insolation.

## Example questions

**1. Which planets are most Earth-like, and in which constellations are their host stars?** (Restricted to hosts you can see with the naked eye.)

```cypher
MATCH (p:Planet)-[:ORBITS]->(s:Star {naked_eye: true})-[:IN]->(c:Constellation)
WHERE p.features IS NOT NULL
WITH p, s, c, vector.similarity.euclidean(p.features, [0.088195, 0.095262, 0.53436, 0.09427, 0.416004]) AS similarity
RETURN p.name AS planet, s.name AS host, round(s.dist_ly, 1) AS dist_ly, c.name AS constellation, round(similarity, 4) AS similarity
ORDER BY similarity DESC LIMIT 10
```

Answer: τ Cet h and τ Cet f (Cetus) lead, then HD 20794 e, d and f (Eridanus).

**2. What's the shortest route from the Sun to TRAPPIST-1 with jumps of 6 ly or less?**

```cypher
MATCH (sun:Star {name: 'Sun'}), (t:Star {name: 'TRAPPIST-1'})
MATCH p = SHORTEST 1 (sun)-[r:NEAR WHERE r.ly <= 6]-+(t)
RETURN [n IN nodes(p) | n.name] AS route, [x IN relationships(p) | x.ly] AS jumps_ly
```

Answer: no rows, there is no such route. To see why, list what is reachable:

```cypher
MATCH (sun:Star {name: 'Sun'})
MATCH (sun)(()-[r:NEAR]-() WHERE r.ly <= 6){1,8}(x:Star)
WHERE x <> sun
RETURN collect(DISTINCT x.name) AS reachable
```

Only five stars are: Proxima Centauri, Rigil Kentaurus, Toliman, Barnard's Star and Ross 154. TRAPPIST-1 is 40.5 ly away.

**3. Which detection method found the most planets each decade?**

```cypher
MATCH (p:Planet)-[:DETECTED_VIA]->(m:Method)
WITH p.disc_decade AS decade, m.name AS method, count(p) AS planets
ORDER BY decade, planets DESC
WITH decade, collect({method: method, planets: planets}) AS ranked, sum(planets) AS total
RETURN decade, ranked[0].method AS top_method, ranked[0].planets AS planets, total
ORDER BY decade
```

Answer: Radial Velocity in the 1990s and 2000s, Transit in the 2010s and 2020s.

**4. Which constellations have the most known planets?**

```cypher
MATCH (p:Planet)-[:ORBITS]->(:Star)-[:IN]->(c:Constellation)
RETURN c.name AS constellation, count(p) AS planets
ORDER BY planets DESC LIMIT 10
```

Answer: Cygnus (1,683) and Lyra, the Kepler field, far ahead of the rest.

**5. Which planet hosts can I see with the naked eye, brightest first?**

```cypher
MATCH (s:Star {naked_eye: true, is_host: true})-[:IN]->(c:Constellation)
RETURN s.name AS star, s.mag AS mag, s.planet_count AS planets, round(s.dist_ly, 1) AS dist_ly, c.name AS constellation
ORDER BY s.mag LIMIT 10
```

## Credits

- Stars: HYG Database v4.4 by David Nash (astronexus), CC BY-SA 4.0. Because of this, sky.rl is shared under CC BY-SA 4.0.
- Planets: NASA Exoplanet Archive, Planetary Systems Composite Parameters (doi:10.26133/NEA13), operated by Caltech under contract with NASA.
- Constellation lines: d3-celestial v0.7.32 by Olaf Frohn, BSD 3-Clause.

Full attribution: https://github.com/dhodapkarsoham/sky-graph/blob/main/ATTRIBUTION.md
