Build a semantic search engine using embeddings and NexaDB's built-in vector search. This example shows how to find similar movies by theme, not keywords.
Insert movies with 4D semantic vectors representing action, romance, sci-fi, and drama levels
Find similar movies using cosine similarity - search by meaning, not keywords
Query for "romantic movies" and get The Notebook (99.9% match) - without using the word "romance"
200x faster than linear scan, perfect for RAG systems and recommendation engines
brew install nexadb)pip install nexaclient or npm install nexaclient)# Start NexaDB
nexadb start
# In another terminal, create your script
touch movie_search.pyfrom nexaclient import NexaClient
# Connect to NexaDB
client = NexaClient(
host='localhost',
port=6970,
username='root',
password='nexadb123'
)
client.connect()
print("Connected to NexaDB!")Each movie has a 4D vector: [action, romance, sci-fi, drama]
# Movie data with semantic vectors
movies = [
{
"title": "The Matrix",
"year": 1999,
"genre": "Sci-Fi/Action",
"embedding": [0.8, 0.2, 0.95, 0.5] # [action, romance, sci-fi, drama]
},
{
"title": "The Notebook",
"year": 2004,
"genre": "Romance/Drama",
"embedding": [0.1, 0.98, 0.05, 0.85]
},
{
"title": "Mad Max: Fury Road",
"year": 2015,
"genre": "Action",
"embedding": [0.99, 0.05, 0.3, 0.4]
},
{
"title": "Inception",
"year": 2010,
"genre": "Sci-Fi/Thriller",
"embedding": [0.7, 0.2, 0.9, 0.6]
},
{
"title": "Titanic",
"year": 1997,
"genre": "Romance/Drama",
"embedding": [0.3, 0.95, 0.1, 0.9]
}
]
# Insert movies
for movie in movies:
result = client.create('movies', movie)
print(f"Inserted: {movie['title']}")
print(f"\nInserted {len(movies)} movies with embeddings!")Search by meaning - find romantic movies without using the word "romance"
# Search for romantic movies
romance_query = [0.1, 0.95, 0.1, 0.8] # Low action, high romance
results = client.vector_search(
collection='movies',
vector=romance_query,
limit=3,
dimensions=4
)
print("\nš¬ Most Romantic Movies:")
for i, result in enumerate(results, 1):
doc = result['document']
similarity = result['similarity'] * 100
print(f"{i}. {doc['title']} ({doc['year']}) - {similarity:.2f}% match")
print(f" Genre: {doc['genre']}\n")Connected to NexaDB!
Inserted: The Matrix
Inserted: The Notebook
Inserted: Mad Max: Fury Road
Inserted: Inception
Inserted: Titanic
Inserted 5 movies with embeddings!
š¬ Most Romantic Movies:
1. The Notebook (2004) - 99.90% match
Genre: Romance/Drama
2. Titanic (1997) - 98.78% match
Genre: Romance/Drama
3. Inception (2010) - 57.45% match
Genre: Sci-Fi/Thrillerconst NexaClient = require('nexaclient');
async function movieSearch() {
const client = new NexaClient({
host: 'localhost',
port: 6970,
username: 'root',
password: 'nexadb123'
});
await client.connect();
console.log('Connected to NexaDB!');
// Insert movies
const movies = [
{
title: "The Matrix",
year: 1999,
genre: "Sci-Fi/Action",
embedding: [0.8, 0.2, 0.95, 0.5]
},
{
title: "The Notebook",
year: 2004,
genre: "Romance/Drama",
embedding: [0.1, 0.98, 0.05, 0.85]
},
{
title: "Mad Max: Fury Road",
year: 2015,
genre: "Action",
embedding: [0.99, 0.05, 0.3, 0.4]
}
];
for (const movie of movies) {
await client.create('movies', movie);
console.log(`Inserted: ${movie.title}`);
}
// Search for romantic movies
const romanceQuery = [0.1, 0.95, 0.1, 0.8];
const results = await client.vectorSearch('movies', romanceQuery, 3, 4);
console.log('\nš¬ Most Romantic Movies:');
results.forEach((result, i) => {
const similarity = (result.similarity * 100).toFixed(2);
console.log(`${i + 1}. ${result.document.title} - ${similarity}% match`);
});
await client.disconnect();
}
movieSearch().catch(console.error);Build ChatGPT-style apps with document retrieval. Store OpenAI/Claude embeddings and find relevant context for prompts.
"Customers who liked this also liked..." using product embeddings. Perfect for e-commerce and content platforms.
Search by meaning instead of keywords. Find "affordable European getaways" without those exact words appearing.
Find similar support tickets, detect plagiarism, or identify near-duplicate records in your database.
Learn about HNSW algorithm, vector dimensions, and performance tuning
Complete movie search demo with 12 movies and multiple search examples
Node.js, Python, NestJS, and more integration examples
Get the full movie search demo with 12 movies and all search examples
Download demo_vector_search.py