File size: 4,941 Bytes
80ceec5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: "TorchDocsAgent β€” documentation index"
kind: index
---

# TorchDocsAgent β€” documentation

This folder is the reasoning behind the code: **why** each part exists, the
logic it follows, and the tool choices it rests on. It has two layers.

- **Cross-cutting design docs** explain the system as a whole β€” the product
  shape, the content pipeline, the agent contract, deployment.
- **Per-package references** (`docs/<package>/README.md`) mirror the code tree
  one-to-one: each documents a single top-level package β€” its boundary, its
  flow, the decisions and their rejected alternatives, and a file-by-file map.

Start with the design docs for the shape of the whole; drop into a package
reference when you're about to touch that package.

## The system in one picture

```
                         the docs.pytorch.org site
                                   β”‚
   ingest/   discover β†’ crawl β†’ chunk           builds the _corpus/ snapshot
                                   β”‚
   index/    embed β†’ Neon (pgvector + tsvector)  storage + hybrid retrieval
                                   β”‚  pointers + hydrated sections
   agent/    guard β†’ route β†’ grounded | loop β†’ llm β†’ Answer   the answering brain
                                   β”‚
   app/      Gradio Space: stream the reasoning, render the answer + citations
                                   β”‚
                              the user

   scripts/  the CLI + CI surface that builds, evaluates, and operates all of the above
   eval/     the measurement layer that keeps every layer honest
```

Data flows down the middle; `scripts/` and `eval/` wrap the column as tooling.
The knowledge boundary is firm: the docs **site** is the corpus, source code is
never indexed (it is referred out), and every answer is grounded in retrieved
sections with clickable citations.

## Per-package references

| Package | What it is | Reference |
|---|---|---|
| **`ingest/`** | The crawl β†’ snapshot β†’ chunk pipeline that turns the live docs site into a heading-chunked corpus. Touches no DB. | [docs/ingest/](ingest/README.md) |
| **`index/`** | The Neon/pgvector storage + retrieval layer: embeddings, hybrid search, DB-served hydration, and the self-healing freshness pass. | [docs/index/](index/README.md) |
| **`agent/`** | The answer-generation brain: guard β†’ route β†’ grounded/loop β†’ LLM dispatch β†’ validated `Answer`. | [docs/agent/](agent/README.md) |
| **`app/`** | The Gradio web app (the Hugging Face Space): serving, concurrency, and the live grey reasoning trace. | [docs/app/](app/README.md) |
| **`eval/`** | The measurement layer: static answer checks, retrieval metrics, and LLM-as-judge β€” wired into CI and the live answer path. | [docs/eval/](eval/README.md) |
| **`scripts/`** | The command-line + CI surface: build the index, generate synthetic data, evaluate, calibrate, and smoke-test. | [docs/scripts/](scripts/README.md) |

## Cross-cutting design docs

| Document | What it covers |
|---|---|
| [design-content-and-agent-flow.md](design-content-and-agent-flow.md) | The architecture bible: corpus scope, the ingestion pipeline, the three agent tools, the session flow, LangChain-vs-LangGraph, and how stored pointers map to live links. Start here. |
| [retrieval-gaps-and-improvements.md](retrieval-gaps-and-improvements.md) | Known retrieval weaknesses and the improvement backlog (reranking, multilingual embedder, judge model, …). |
| [loop-vs-langgraph.md](loop-vs-langgraph.md) | The measured comparison of the manual tool loop (`agent/loop.py`) against its LangGraph twin (`agent/graph.py`). |
| [deploy-hf-spaces.md](deploy-hf-spaces.md) | The Hugging Face Spaces deployment walkthrough β€” secrets, the sync workflow, and the post-deploy smoke test. |

See also [PLAN.md](../PLAN.md) for the milestone roadmap and the binding
decisions that constrain execution.

## Suggested reading order

1. [design-content-and-agent-flow.md](design-content-and-agent-flow.md) β€” the whole shape in one read.
2. [docs/ingest/](ingest/README.md) β†’ [docs/index/](index/README.md) β€” how the corpus is built and retrieved (data flows up from here).
3. [docs/agent/](agent/README.md) β€” how a question becomes a grounded answer.
4. [docs/app/](app/README.md) β€” how it is served and streamed to the user.
5. [docs/eval/](eval/README.md) and [docs/scripts/](scripts/README.md) β€” how it is measured and operated.

## Conventions

- Each package reference has YAML frontmatter (`title`, `kind: reference`,
  `package`), then: boundary β†’ flow β†’ design decisions & rationale β†’ tool
  choices β†’ file-by-file β†’ related docs.
- Docs describe the **code as written**, not an idealized plan. Where a plan
  item is unbuilt or a decision was superseded, the doc says so.
- These are OKF-style knowledge documents (markdown + frontmatter), the same
  convention the corpus chunks and the other `docs/*.md` reports use.