liveBook · Manning

Information retrieval

As explained in MongoDB 8.0 in Action, Third Edition

Information retrieval is the process of finding relevant information from a collection of stored data in response to an information need.

Information retrieval finds relevant information in stored data in response to a query. In document collections, that can mean ranking text by relevance rather than requiring an exact-word match. In retrieval-augmented generation (RAG), it means finding external information that a language model can use when composing an answer. section 11.0 section 14.0

Choose a retrieval method for the information need:

  • Use keyword and Boolean searches to find terms and narrow results with AND, OR, or NOT. section 11.0
  • Use fuzzy or wildcard search when spelling or word forms vary; use phrase or proximity search when wording and context matter. section 11.0
  • Use range and faceted search to restrict and categorize results by attributes, such as dates or product features. section 11.0
  • Use vector search to retrieve relevant data for RAG when generating answers grounded in external information. section 1.0 section 14.0

Implementation affects operations. MongoDB’s basic $text index may be insufficient for complex searches across nested fields. A separate search engine adds data replication, monitoring, maintenance, and possible consistency problems. Atlas Search instead integrates Apache Lucene-based full-text search with MongoDB Atlas; its inverted indexes map terms to document locations, while the mongot process keeps search indexes updated through change streams. section 11.1 section 11.8

Figure 11.1 High-level data synchronization architecture. The application uses separate drivers and query languages to interact with the database and search clusters. Data is replicated from the database cluster to the search cluster to keep the index updated. This setup adds complexity, increases resource usage, and can lead to consistency issues. (Image © MongoDB 2024 CC BY-NC-SA 3.0)
A diagram of a computer language

Description automatically generated

The synchronization diagram shows why a separate database and search cluster require additional drivers, queries, and replication—and where consistency risks arise. section 11.1

Retrieve and rank local inspection records

In a logged-in local Atlas cluster, create a dynamic search index with db.inspections.createSearchIndex("LocalSearchIndex", { mappings: { dynamic: true } }), then check getSearchIndexes() for readiness. Run an aggregation using $search to query the result and business_name fields for “No Violation Issued,” allowing two edits for typos. Apply $match for the desired sector and city, add the searchScore, sort by that score, and limit output to three records. Drop the index with dropSearchIndex() when finished. Dynamic mapping suits this test environment; selective static mappings can avoid indexing unwanted fields. section 13.5.1 section 11.8

Listing 13.2 Executing a full-text search locally
db.inspections.aggregate([
  {
    $search: { #1
      index: 'LocalSearchIndex', #2
      text: {
        query: 'No Violation Issued', #3
        path: ['result', 'business_name'], #4
        fuzzy: {
          maxEdits: 2 #5
        }
      }
    }
  },
  {
    $match: { #6
      sector: 'Cigarette Retail Dealer - 127', #7
      'address.city': 'RIDGEWOOD' #8
    }
  },
  {
    $addFields: { #9
      score: { $meta: "searchScore" }
    }
  },
  {
    $sort: { #10
      score: -1
    }
  },
  {
    $limit: 3 #11
  },
  {
    $project: { #12
      _id: 0, #13
      business_name: 1,
      certificate_number: 1,
      date: 1,
      result: 1,
      'address.street': 1,
      'address.number': 1,
      'address.zip': 1,
      score: 1 #14
    }
  }
])

The complete aggregation illustrates how fuzzy retrieval, structured filters, relevance ranking, and projection work together. section 13.5.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains search modes, inverted indexing, operational trade-offs, and a worked local query; stops short of implementing a search engine.
Examples
Demonstrates fuzzy inspection-record search with sector and city filters, relevance scores, and a three-result limit.
What it assumes
Introduces search capabilities and indexing before the local exercise, which begins after login to a local cluster.
What you can do after
Apply it via Atlas Search by creating a local index and querying, filtering, and ranking collection results.
How it connects
Connects full-text search to inverted indexes, aggregation pipelines, vector search, and retrieval-augmented generation.

Also explained in

Compare how 11 books explain information retrieval →

Related concepts

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