Chromia
Start Building

11 / 15Advanced

Search the vector database

With your movie data on-chain, complete with vector embeddings and full metadata, you can run semantic searches in natural language and get back the closest matches.

Activate vector_demo_env if it isn't active yet

From the rell/ folder:

bash
cd ../python

From the project root:

bash
cd python

Next, activate the environment:

bash
source vector_demo_env/bin/activate

Run the script

Go to the python/ folder and run this command:

bash
python search_movies.py

At the prompt, type a search query, such as:

text
A man wakes up in a world controlled by machines.

The script then does three things:

  • Generates an embedding for your query with the model set in your .env file
  • Queries the on-chain vector index for the nearest embeddings
  • Returns the best-matching movies together with their metadata

Filter your search by genre (optional)

A second version of the script lets you restrict results to a genre:

bash
python search_movies_filtered.py

It behaves the same as the standard search, except that it asks you for a genre before it runs the query.

For instance:

  • Query: A robot gains self-awareness
  • Genre: Science Fiction

You get back only semantically relevant results from that genre.

What’s included in the results?

Every result shows:

  • Title
  • Release date
  • Plot summary
  • Genres, languages, and countries
  • Similarity score (a distance, so lower means more similar)

Because similarity comes from vector distance, results match on meaning, not just on shared words.

Try your own queries

Some prompts to experiment with:

  • A woman leads a rebellion against a dystopian regime
  • Movies about AI taking control of humanity
  • Stories involving time travel and paradoxes
  • A team of explorers enters another dimension

Use them with the standard script, or pair them with a genre filter in search_movies_filtered.py.

What’s next?

The next module looks under the hood: how Rell stores and queries vectors and links them to movie metadata.

Written for this site from Chromia’s public course. Code samples are the course’s own.