Skip to content

This project demonstrates how to define vector-indexed fields, configure vector search indices, and execute similarity queries using Spring Data MongoDB

License

Notifications You must be signed in to change notification settings

mongodb-developer/spring-data-mongodb-hybrid-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-data-mongodb-hybrid-search

This project is part of the “Beyond Keywords” article series, where we explore how to go beyond simple keyword search and build smarter applications with MongoDB and Spring.

It started with semantic search using vector search and Voyage AI embeddings, then evolved to include pre-filters for more precise results, caching strategies to save on embedding generation, and finally Hybrid Search — combining Atlas Search (full-text) with vector search through $rankFusion.

The project demonstrates:

  • Vector Search with pre-filters (e.g., genres, year, IMDb rating).
  • Atlas Search with compound queries, filters, and should clauses.
  • Caching strategies to avoid unnecessary embedding calls.
  • Hybrid Search that merges vector similarity and keyword matching.

It also includes a minimal Bootstrap-based UI served by Spring (/static/index.html) and a REST endpoint.

The Movie Search web application

Built With

Getting Started

1. Clone the repository

git clone https://github.com/mongodb-developer/spring-data-mongodb-hybrid-search.git

2. Set the environments variables

cd spring-data-mongodb-hybrid-search
export MONGODB_URI="<YOUR_CONNECTION_STRING>" VOYAGE_API_KEY="<API_KEY>"

3. Run the application

mvn spring-boot:run

3.1 Use the API (endpoint):


POST http://localhost:8080/movies/search
Content-Type: application/json

{
  "query": "a ship that sinks at night after hitting an iceberg",
  "minIMDbRating": 5,
  "yearFrom": 1980,
  "yearTo": 2003,
  "genres": [
    "Drama", "Action"
  ],
  "excludeGenres": false
}

Or Open the app

http://localhost:8080/

Use the search bar to find movies (renders title, year, and full plot).

The Movie Search web application

About

This project demonstrates how to define vector-indexed fields, configure vector search indices, and execute similarity queries using Spring Data MongoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published