Overview

Appendix A. Vector Search with Storage

This appendix explains how to add semantic search to the RSS reader built earlier by extending the existing storage layer rather than redesigning the application. It begins by contrasting keyword search with vector search, showing why exact word matching misses relevant content when users phrase questions differently or when related concepts are expressed with different terms. Semantic search addresses this by turning text into embeddings, numeric vectors that place related meanings close together in vector space.

The implementation uses Ollama to generate embeddings locally and Qdrant to store and search those vectors efficiently. The storage module is expanded with clean domain interfaces for embedding and search, and the design favors a decorator pattern: a searchable wrapper adds vector indexing and semantic lookup on top of any storage backend while leaving the underlying persistence code unchanged. Article data continues to live in bbolt, while Qdrant holds vector representations and metadata for similarity search, with context support added to allow cancellation and timeouts during embedding generation.

The final integration shows how the same wrapped storage instance can serve both traditional CRUD handlers and a new search handler through interface segregation. When articles are added, they are first persisted to bbolt and then embedded and stored in Qdrant, with failures in the search path logged but not allowed to break core storage. At query time, the search endpoint embeds the user’s query, finds the nearest vectors in Qdrant, and fetches the matching articles from bbolt, delivering results ranked by semantic similarity while preserving backward compatibility and graceful degradation if the vector services are unavailable.

A.4 Summary

  • Vector search finds content by semantic meaning rather than exact keyword matches, using embedding models that convert text into high-dimensional numerical vectors representing meaning.
  • The decorator pattern allows you to add search capabilities to any existing Storage implementation without modifying it. SearchStore wraps the base storage, delegating CRUD operations while adding embedding generation and search.
  • Interface segregation keeps dependencies minimal—handlers depend only on Storage (for CRUD) or Searchable (for search), not both. The SearchableStorage interface combines them through composition when needed.
  • The dual write pattern maintains consistency across storage systems: bbolt serves as the source of truth for article persistence, while Qdrant provides the search index. Secondary write failures don’t fail the operation, providing eventual consistency.
  • Graceful degradation ensures system resilience—if vector search infrastructure (Qdrant or Ollama) fails, the system continues operating with traditional storage, logging warnings but maintaining core functionality.
  • Qdrant (vector database) and Ollama (embedding service) enable local semantic search capabilities without cloud dependencies, using Docker Compose for straightforward local development and deployment.

FAQ

What is the main goal of Appendix A in the book?The appendix shows how to add semantic vector search to the existing RSS reader system by extending the storage module, while keeping the architecture simple and focused.
Why is vector search better than traditional keyword search for this use case?Vector search understands semantic meaning instead of exact word matches, so it can find relevant articles even when the query uses synonyms or different wording than the article text.
What is a vector embedding?A vector embedding is a numerical representation of text, usually an array of floating-point numbers, where similar meanings produce similar vectors in high-dimensional space.
How does the appendix generate embeddings?It uses Ollama running locally with the nomic-embed-text model to convert article text and user queries into 768-dimensional vectors.
Why are Qdrant and Ollama used together?Ollama generates the embeddings, and Qdrant stores and searches those vectors efficiently using similarity search algorithms.
What is the purpose of the Docker Compose setup?Docker Compose makes it easy to run Qdrant and Ollama locally, persist their data in volumes, and expose the needed ports for the Go application.
What interfaces are added to support semantic search?The appendix adds Embedder for text-to-vector conversion, Searchable for semantic search, and SearchableStorage to combine storage and search capabilities.
How does the decorator pattern work in SearchStore?SearchStore wraps an existing Storage implementation, delegates normal storage methods to it, and adds embedding generation plus vector search without changing the original storage code.
What happens when articles are added through SearchStore?First the articles are saved in the underlying storage, then their title and description are embedded and stored in Qdrant for later semantic search.
How does the API expose semantic search to clients?The API adds a /search endpoint that accepts a query and limit, uses the Searchable interface, and returns articles ranked by similarity score.

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