Guo Note Technical Documentation
website·Indexed 30 days ago
https://guo-note.pages.devA collection of technical notes covering network protocols (HTTP/3, QUIC, DNS, Cookies), sorting algorithms (Quick Sort, Merge Sort, Heap Sort, etc.), and AI optimization strategies including token saving, context compression, and prefix caching.
What's inside Guo Note
- Token governance in LLM applications focuses on reducing API costs, decreasing Time To First Token (TTFT), and improving model attention. The optimization pipeline typically follows this flow: Model Routing/Gateway $\rightarrow$ Caching Layer $\rightarrow$ Context Compression $\rightarrow$ Agent Toolchain Optimization $\rightarrow$ Format Optimization $\rightarrow$ LLM Inference $\rightarrow$ Output Simplification $\rightarrow$ Memory Archiving.
Understand how HTTP Cookies manage state
HTTP is a stateless protocol, meaning each request is independent. Cookies provide servers with a 'memory' by allowing them to send data to the browser in a response. The browser stores this data and automatically includes it in subsequent requests to the same server, enabling the server to identify the user and maintain session state.Compare Context Compression, RAG, and Prefix Caching
These three techniques serve different roles in an AI architecture and are often used together:
- RAG (Retrieval Augmented Generation): Finds relevant data from a massive knowledge base. It does not reduce the text itself but selects which text to include.
- Context Compression: Refines and 'squeezes' the retrieved data or conversation history to reduce token count, lower cost, and remove noise.
- Prefix Caching: Stores the computed state of a fixed prefix (like a System Prompt) to avoid redundant GPU calculations, speeding up subsequent calls without changing the text.
Recommended Workflow: RAG (Retrieve 15 docs) $\rightarrow$ Context Compression (Filter to 2 core docs) $\rightarrow$ Prefix Caching (Cache the System Prompt).
Understand the role of the Harness in AI Agents
In the context of AI Agents, the architecture is defined asAgent = Model + Harness. While the Model determines the upper bound of reasoning capability, the Harness is responsible for environment perception, session management, tool orchestration, context stitching, and protocol interaction. The engineering quality of the Harness—specifically its ability to maintain a high Cache Hit rate—is a critical factor in determining the stability and operational cost of the Agent.Understand HTTP/3 and QUIC protocol characteristics
HTTP/3 is built on the QUIC protocol to completely resolve the 'Head-of-Line (HOL) blocking' issue, providing better performance in weak network environments compared to HTTP/2. QUIC is a transport layer protocol built on top of UDP that ensures reliable transmission.Understand TCP Head-of-Line Blocking in HTTP/2
While HTTP/2 solves head-of-line (HOL) blocking at the application layer using streams and multiplexing, it still suffers from HOL blocking at the transport layer (TCP). Because TCP ensures reliable, ordered delivery, if a single packet is lost during transmission, TCP must wait for the retransmission of that specific packet before any subsequent packets (even if already received and stored in the buffer) can be delivered to the application layer. This creates a bottleneck where all streams in an HTTP/2 connection are stalled by a single lost TCP segment.QUIC Protocol Overview and Key Features
QUIC is a transport layer protocol designed to replace TCP for HTTP/3. It is built on top of UDP to eliminate the inherent head-of-line blocking of TCP. Key characteristics include:
- Reliability: Implements connection management, congestion control, and flow control similar to TCP but over UDP.
- Multiplexing: Supports multiple streams. A packet loss in one stream does not block other streams.
- Integrated Encryption: Incorporates TLS 1.3 directly into the protocol rather than layering it on top, enabling 0-RTT and 1-RTT connection establishment.
- Connection Migration: Uses an opaque 'Connection ID' instead of the traditional IP/Port 4-tuple. This allows a connection to remain active even if the client's IP address changes (e.g., switching from 4G to WiFi).
HTTP/3 Protocol Architecture and Frame Changes
HTTP/3 maps its request-response model directly onto QUIC streams. Because QUIC handles encryption, flow control, and multiplexing, the HTTP/3 layer is simplified:
- Stream Mapping: Bidirectional QUIC streams map to HTTP/2 streams; unidirectional QUIC streams are used for control and server push (similar to HTTP/2 stream 0).
- Simplified Frames: Frames only contain 'Type' and 'Length' (variable-length encoding).
- Removed Frames: Frames like
RST_STREAM,WINDOW_UPDATE, andPINGare removed from HTTP/3 because they are now handled by the underlying QUIC layer. - QPACK Compression: Replaces HPACK. To avoid HOL blocking, QPACK prohibits updating the dynamic table within a HEADERS frame; updates must be sent on a dedicated unidirectional control stream. The static table is expanded to 98 entries.
Understand the purpose and benefits of LLM context compression
Context compression is the process of reducing the length of the input (context) provided to a Large Language Model (LLM)—such as chat history, reference documents, or system prompts—while preserving key information. This is used to address four primary pain points:
- Cost: Reducing token count directly lowers API expenses (potentially by 70-80%).
- Latency: Shorter inputs improve Time to First Token (TTFT) and overall response speed.
- Accuracy: It mitigates the 'Lost in the Middle' phenomenon where models ignore key details buried in long inputs, leading to more precise answers.
- Memory Management: It prevents multi-turn Agent interactions or long conversations from exceeding the model's maximum context window.
Reduce output tokens through formatting and constraints
Since output tokens are typically 3-5x more expensive than input tokens, applying output-side compression is highly effective:
- Prompt Constraints (Caveman style): Use system prompts to forbid polite fillers, introductory phrases, and prose, forcing the model to output only core points and code. This can reduce output tokens by 30% to 65%.
- TOON Format: For structured JSON, declare the Schema once and transmit subsequent batch data as pure value arrays. This can halve the tokens used for structured data.
- Compact Protocols: Remove whitespace/indentation, abbreviate common keys, and use compact YAML instead of verbose JSON for nested structures. This reduces format overhead by 20% to 40%.
Understand the Heap Sort algorithm steps
The Heap Sort process consists of the following logical steps:
- Create a heap $H[0 – n-1]$ from the input array.
- Swap the root of the heap (which contains the maximum value in a max-heap) with the last element of the current heap.
- Decrease the effective size of the heap by 1.
- Call a
shift_down(orheapify) operation on the root to move the new root element to its correct position and restore the max-heap property. - Repeat steps 2 through 4 until the heap size is reduced to 1.
Discover HTTP/3 Services via Alt-Svc
HTTP/3 does not have a globally mandated default port. Service discovery is handled via HTTP/2 using the
Alt-Svc(Alternative Services) extension frame.Discovery Process:
- The browser establishes an HTTP/2 connection to the server.
- The server sends an
Alt-Svcframe containing a string likeh3=host:port. - The browser attempts an asynchronous QUIC connection to the specified endpoint.
- If successful, the browser switches from HTTP/2 to HTTP/3 for subsequent data exchange.