Rickesh commited on
Commit
0852758
·
verified ·
1 Parent(s): 4c5820e

Upload ctxstream/README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. ctxstream/README.md +91 -0
ctxstream/README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ctxstream
2
+
3
+ Stream an oversized context past a small model, then construct the answer in code.
4
+
5
+ Zero third-party dependencies. C++17.
6
+
7
+ ## Why
8
+
9
+ Measured on a 4B model over a 261,226-token corpus on a 6GB card: the model swept
10
+ every segment correctly, was asked which label was least common, and answered
11
+
12
+ Status: beta, Status: delta, Status: gamma, Status: alpha
13
+
14
+ It listed the candidates instead of selecting one. An earlier run with 65 segments
15
+ combined the partial counts wrongly. Same mistake both times, and it was the
16
+ harness's, not the model's: a language model was asked to plan a traversal *and*
17
+ to do aggregation arithmetic.
18
+
19
+ ctxstream takes both jobs away from it.
20
+
21
+ | video streaming | ctxstream |
22
+ |---|---|
23
+ | manifest / playlist | segment plan, computed in code, before any model call |
24
+ | buffer | N segments in flight, latency hidden behind compute |
25
+ | decoder | model sees ONE segment, emits `key<TAB>number`, never prose |
26
+ | playback | reduce phase — a strategy you choose, in code |
27
+
28
+ The model's only job is extraction from a window it comfortably fits.
29
+
30
+ ## Codebase mode
31
+
32
+ A directory input is not treated as a character stream. Cutting code every N chars
33
+ splits functions and separates a call from its definition. Instead:
34
+
35
+ 1. **scan** — walk the repo, skip excluded dirs and binaries, record what was
36
+ skipped and why
37
+ 2. **graph** — symbols (function/class/struct) per file, plus file→file edges from
38
+ `#include` / `import` / `require`
39
+ 3. **order** — dependency-first, so a file follows what it includes
40
+ 4. **segment** — on file boundaries, never mid-symbol; oversized files fall back to
41
+ line-boundary splitting
42
+
43
+ ```bash
44
+ ctxstream --input ./my-repo --graph-only # inspect the graph
45
+ ctxstream --input ./my-repo --extract "..." # graph, then stream
46
+ ```
47
+
48
+ ## Build
49
+
50
+ ```bash
51
+ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
52
+ cmake --build build -j
53
+ ./build/test_ctxstream # 61 checks, no model or network needed
54
+ ```
55
+
56
+ ## Use
57
+
58
+ ```bash
59
+ ctxstream --input corpus.txt \
60
+ --extract "Count how many lines carry each category value in this fragment." \
61
+ --answer least --label Category \
62
+ --model gemma4:e4b --num-ctx 32768 --segment-chars 60000
63
+ ```
64
+
65
+ `--answer` is `least | most | total | list`. `--plan-only` prints the segment plan
66
+ and exits without calling a model.
67
+
68
+ ## Guarantees it actually enforces
69
+
70
+ - **Full coverage.** Every byte lands in some segment; tests assert it. A planner
71
+ that drops the tail yields a confident answer over partial data.
72
+ - **No mid-record cuts.** Segments snap back to a record boundary.
73
+ - **Truncation is fatal, not silent.** A server that clips the prompt and answers
74
+ from the remainder is caught by comparing reported prompt tokens against what
75
+ was sent. Measured case: 50,000 tokens sent, 16,387 processed, no error raised.
76
+ - **A partial sweep refuses a headline answer.** If any segment failed, every key
77
+ is undercounted, so `--answer least/most/total` exits non-zero rather than
78
+ printing a number.
79
+ - **Keys with spaces survive.** `Spatial Relationship` must not become `Spatial`.
80
+
81
+ ## Layout
82
+
83
+ ```
84
+ src/ctxstream.hpp types + API
85
+ src/manifest.cpp segment planning (text)
86
+ src/codegraph.cpp repo scan, symbols, edges, graph-aware segmentation
87
+ src/backend.cpp HTTP/1.1 + minimal JSON, no libcurl
88
+ src/pipeline.cpp concurrent streaming, retries, progress
89
+ src/reduce.cpp record parsing, tally, answer construction
90
+ src/main.cpp CLI
91
+ ```