Skip to content

store-craft/mongodb-semantic-search-example

Repository files navigation

Storecraft + MongoDB Livestream of Semantic Vector Search extension and frontend



tomer

This repo was created during the livestream we had th the official MongoDB YouTube channel.

We demo the usage of Storecraft with Mongo Vector Search

Watch on Youtube

What we did:

  • We created an extension for Storecraft, that adds semantic/ai search for products catalog.
  • We implemented a small frontend react application to demonstrate the vector search.

How to run

First,

First, make sure you have the following environment variables

//.env

OPENAI="YOUR OPENAI KEY"
MONGODB_URL="YOUR MONGODB CONNECTION URL"

Then,

npm install
npm run migrate
npm start

Setup semantic/ai vector index in Mongo Atlas

  1. in Atlas dashboard, create a vector index (call it vector_index) for products collection:
{
  "fields": [
    {
      "numDimensions": 1536,
      "path": "embedding",
      "similarity": "cosine",
      "type": "vector"
    }
  ]
}

Now,

  • Open dashboard at http://localhost:8080/api/dashboard
  • Upsert some products so every upserted product will be indexed for semantic search by it's title and description.

Webapp

And then, follow the instructions in the ./frontend folder to start the web app.