# Sighting story

A language model writes a short, dated timeline of a vulnerability from the texts of
its sightings: mailing-list messages, patches, posts. It is an optional module, off by
default, and needs an [Ollama](https://ollama.com) server.

## Enabling it

```python
# config/website.py
WEB_MODULES = {
    "sighting_story": True,
}

OLLAMA_URL = "http://127.0.0.1:11434"
SIGHTING_STORY_MODEL = "qwen3.8:27b"
SIGHTING_STORY_TIMEOUT = 300  # seconds the website waits for one story
```

- Install the model on the Ollama server: `ollama pull qwen3.8:27b`.
- The texts of the sightings are sent to that server. Run one you control.
- A story takes seconds on a GPU. Without one, choose a smaller model: it takes
  minutes, and a large model may not fit in memory.
- User accounts must be enabled: only logged-in users can ask for a story.

## Using it

- On a vulnerability page, the **Sighting correlations** tab shows a
  **Generate the story** button to logged-in users.
- The button opens `/vuln/<id>/story`, which waits for the model and then shows the
  summary, the timeline, the related vulnerabilities and the numbered sources.
- Under the story: the model, the time the generation took, and the tokens the model
  read and wrote.
- A vulnerability needs at least two sightings that carry a text.
- Each user may ask 20 times per hour.

## What is sent to the model

- One document per source, its earliest sighting, in chronological order.
- At most 40 documents and 30,000 characters in total. Past 40, the 20 earliest and
  the 20 latest are kept. A document that was cut is marked as such on the page.
- In a reply, the lines quoted from an earlier document are removed.
- The other vulnerabilities sighted by the same sources, as in the correlations graph.
- The model does not fetch the sources: it reads what the sighting stored.

## Cache

- A story is stored for 30 days under the hash of the prompt, the model and the
  documents.
- Another user who asks while the sightings are unchanged gets the same story, without
  a new call to the model.
- A new sighting with a text, or another model, gives a new story.
- A failure is kept for one minute, then the story can be asked for again.

## Untrusted texts

The texts come from anyone, and may try to give instructions to the model.

- The model has no tool, and its answer is shown as plain text, never as HTML.
- The answer must follow a JSON schema that only allows the numbers and dates of the
  documents and the related identifiers found in the database. It is checked again by
  the website; an event that cites no existing document is dropped.
- The links of the page come from the database. Anything in the answer that looks like
  a URL is removed.

This limits what a hostile message can do. It does not make the story true: a message
that states something false is a document like the others, and the model can misread a
patch. The page says so, and links every statement to its sources.
