Overview

Appendix B. LLM-Powered Summarization

This appendix extends the news reader from vector search into LLM-powered summarization. Instead of stopping at a ranked list of relevant articles, the system now feeds those retrieved results into a local language model to produce readable prose. The result is a /summary endpoint that can either digest the most recent articles or, when given a topic, summarize only the articles most semantically related to that topic.

The core architecture keeps retrieval and generation cleanly separated. Qdrant remains responsible for finding similar articles, while Ollama serves both the embedding model used for search and the generation model used for summaries. A new summarizer package wraps the LLM integration through a stable interface, and the project uses a retrieval-augmented generation flow so summaries are grounded in the feed’s actual content rather than general model knowledge. Prompt design, temperature, token limits, and timeouts are treated as important tuning points for balancing quality, speed, and reliability.

The API wiring is intentionally additive and modular. The summary handler accepts storage and search interfaces plus the summarizer, then chooses between a fast recent-articles path and a topic-based search-and-summarize path. The main server only gains configuration for the LLM model and a new route, while the rest of the application stays unchanged. The chapter closes by testing both modes end to end and encouraging further exploration through smaller models, prompt refinement, streaming, caching, and failure testing to better understand the trade-offs of local AI integration.

Figure B.1 RAG request pipeline: the two code paths through the system. When a topic is provided, the query is embedded by nomic-embed-text and Qdrant retrieves the most semantically similar articles; those articles are then sent to llama3 for synthesis into prose. Without a topic, the most recent articles are fetched directly from bbolt and passed to llama3, skipping the vector search step entirely.
CH0B F01 Holmes
Figure B.2 Component architecture showing how the packages depend on one another and the external services each talks to
CH0B F02 Holmes

B.7 Summary

  • Retrieval-augmented generation (RAG) grounds LLM output in real data: the /summary?prompt=X endpoint uses vector search to find relevant articles first, then synthesizes them with the LLM, ensuring every claim in the summary comes from your actual feed.
  • The Summarizer package wraps Ollama’s llms.Model interface via langchaingo. Swapping to a different LLM provider (OpenAI, Anthropic) requires changing only the initialization in New(); Summarize() and buildPrompt() are unchanged.
  • Interface segregation carries forward from Appendix B: SummaryHandlers depends on domain.Storage for article retrieval and domain.Searchable for vector search, accepting them as separate parameters even though one concrete value satisfies both.
  • Prompt engineering is the primary control surface for LLM behavior. The same model, same articles, and same code produce substantially different output depending on whether focusTopic is set. Adjusting the prompt is the first tool to reach for when output quality isn’t where you want it.
  • Temperature and token limits are the primary dials for controlling LLM output. Temperature governs randomness (0.0 = deterministic, 1.0 = highly creative); token limits govern response length and generation time. Tuning both is a normal part of integrating an LLM, not a one-time setup step.
  • Ollama serves both the embedding model (nomic-embed-text) and the generation model (llama3) from the same port. No additional infrastructure is required beyond what Appendix B already established.

FAQ

What is the main goal of Appendix B. LLM-Powered Summarization?Appendix B extends the news reader so it can turn retrieved articles into a human-readable summary. Instead of only returning ranked search results, the system uses an LLM to synthesize those articles into a short digest or topic-focused narrative.
How does the /summary endpoint work in the application?The /summary endpoint works in two modes. Without parameters, it summarizes the most recent articles. With ?prompt=<topic>, it first performs semantic search to find relevant articles, then sends those articles to the LLM for summarization.
Why does this chapter use retrieval-augmented generation (RAG)?RAG is used so the LLM’s output is grounded in the app’s actual article data. The system retrieves relevant articles first, then asks the model to generate a response based on those documents, which makes the summary more relevant and less likely to rely on stale model knowledge.
What roles do Qdrant and Ollama play in the summarization pipeline?Qdrant handles retrieval by finding semantically similar articles using vector search. Ollama handles model execution locally: it runs nomic-embed-text for embeddings and llama3 for text generation.
Why is Ollama useful for local development?Ollama lets you run models on your own machine, so no data leaves your system. It also avoids cloud API keys and per-token costs. The trade-off is that CPU-based generation is slower, though a GPU can speed it up significantly.
Why does the appendix introduce a separate summarizer package?The summarizer is separated to keep LLM-specific code isolated from the API layer. This makes the code easier to maintain, keeps dependencies clean, and allows the summarizer to be reused by future tools such as a worker or CLI.
What does the Summarizer type store and how is it initialized?Summarizer holds a live LLM client. It is created with a Config containing the Ollama URL and model name. The New function initializes the Ollama client and returns a ready-to-use summarizer.
Why are temperature and max tokens important in summary generation?Temperature controls how deterministic or creative the output is, and 0.7 is used as a practical balance for readable summaries. MaxTokens limits response length and helps control generation time, since longer outputs take more time to produce.
How does the summary handler decide between recent articles and topic search?The handler checks whether the prompt query parameter is present. If it is empty, it calls GetRecent(count) on storage. If it is set, it calls Search(ctx, prompt, count) to run the full vector-search pipeline before summarizing.
What should be done if the local machine has limited memory?If the machine has less than 8GB of RAM, the appendix recommends using llama3.2:3b instead of llama3. The smaller model is faster and lighter, though it may produce lower-quality summaries.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Go in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Go in Action, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Go in Action, Second Edition ebook for free