liveBook · Manning

Optimization

As explained in Generative AI in Action

Optimization is the improvement of software or model behavior toward a desired objective such as efficiency, quality, or resource use.

Optimization improves a generative AI application toward better quality, efficiency, scalability, or cost. In prompt management, it means continuously refining prompts using performance data while controlling token use and response complexity. section 10.3.4 section 11.5.1

Practical optimization techniques include:

  • Track accuracy, relevance, user feedback, response quality, latency, throughput, and token usage before changing the system. section 10.3.4 section 11.5.1
  • Refine prompts by removing unnecessary text, reducing complexity, and producing shorter outputs without compromising quality. section 10.3.4 section 11.5.1
  • Use caching for frequently requested information to reduce latency and computational load. section 11.5.1
  • Distribute traffic with load balancing and adjust capacity through auto-scaling when demand changes. section 11.5.1
  • Control spending with token monitoring, quotas, or rate limiting to prevent unexpected usage spikes. section 11.5.1

Production optimization loop

Measure an application's quality, relevance, latency, throughput, and token usage; refine prompts or outputs where results fall short; then test the application under different loads. Prometheus and Grafana can support metric collection and visualization, while Apache JMeter or Locust can simulate multiple users. Continue monitoring real-world data and adjust caching, capacity, and usage controls as demand changes. section 10.3.4 section 11.5.1

How Generative AI in Action covers it

How deep it goes
Provides actionable techniques and monitoring concerns but stops short of mathematical derivation or model-internal optimization.
Examples
Uses prompt refinement, token management, caching, monitoring, load testing, load balancing, auto-scaling, quotas, and rate limiting.
What it assumes
Assumes familiarity with LLM inputs, responses, prompts, token limits, and application performance metrics.
What you can do after
Apply it via monitoring, performance testing, prompt refinement, caching, scaling, and usage controls to improve a GenAI application's operation.
How it connects
Connects prompt engineering, PromptOps, evaluation, content moderation, monitoring, performance testing, caching, load balancing, auto-scaling, and cost management.

Also explained in

Compare how 30 books explain optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.