liveBook · Manning

Brute-force search

As explained in Natural Language Processing in Action, Second Edition

A brute-force search algorithm evaluates candidates directly, typically examining all available possibilities to find a match or optimum.

Brute-force search compares candidates directly, usually checking every available possibility until it finds the best match. It favors exactness and simplicity over speed at scale. section 4.8.1

Applied systems use the technique in two especially clear ways:

  • A chatbot can compare an input with stored statements using Levenshtein distance, then reuse the response attached to the closest match. section 1.9
  • Semantic search can compare a query vector with every document vector using cosine similarity, producing precise matches without an index. section 4.8.1
  • The trade-off is structural: processing every candidate requires O(N) work per query, so performance grows only linearly with the corpus. section 4.8.1

From chatbot replies to semantic retrieval

ChatterBot can support a convincing conversation by searching its statement–response database for the closest input, without tokenization or feature generation. The same direct-search idea becomes costly when matching a query against many high-dimensional document vectors, motivating locality-sensitive hashing and approximate nearest-neighbor methods. section 1.9 section 4.8.1

Figure 4.5 Semantic search accuracy deteriorates at around 12 dimensions
figure

Use the accuracy figure to relate exhaustive exact matching to the practical need for approximate search in higher-dimensional vector spaces. section 4.8.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains candidate comparison, similarity measures, and O(N) scaling, but defers efficient indexing and approximate-search implementations.
Examples
Uses ChatterBot statement–response matching and document-vector comparison as concrete applications.
What it assumes
Assumes familiarity with string similarity, vectors, cosine similarity, and basic chatbot or search pipelines.
What you can do after
Evaluate when exact candidate comparison is practical and recognize when corpus size makes approximate retrieval preferable.
How it connects
Connects string matching, edit distance, cosine similarity, semantic search, locality-sensitive hashing, and approximate nearest neighbors.

Also explained in

Compare how 7 books explain brute-force search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.