liveBook · Manning

Mxbai-embed-large

As explained in Just Use Postgres!

mxbai-embed-large is an open-source embedding model that produces 1,024-dimensional vector representations.

mxbai-embed-large is an open-source embedding model that converts text into 1,024-dimensional vectors. A movie application can embed each movie’s name and description, then store the result in a pgvector column for semantic search. section 8.3.1

A practical embedding workflow:

  • Fetch each movie’s name and description from Postgres. section 8.3.1
  • Concatenate the fields with a space and generate an embedding. section 8.3.1
  • Store the vector in a VECTOR(1024) column and compare it with query embeddings. section 8.3.1 section 8.4.1
  • Use the nearest movies as context for a retrieval-augmented generation workflow. section 8.6.3

Semantic movie search

For the query “May the force be with you,” cosine-distance search returns Star Wars: Episode VI - Return of the Jedi and The Acolyte among the top results, even though the exact phrase is absent from their stored descriptions. The example also shows that embedding search can produce an apparently unrelated result, so retrieved matches require evaluation. section 8.4.1

Listing 8.4 Pseudo-code for generating movie embeddings
# Fetch all movies from the database
movies = database.execute("SELECT id, name, description FROM omdb.movies")

# Iterate over each movie and generate the embedding
for each movie in movies:
    id = movie.id
    name = movie.name
    description = movie.description

    # Combine name and description for embedding
    combined_text = name + " " + description

    # Generate embedding using the model
    embedding = embedding_model.generate_embedding(combined_text)

    # Update the database with the generated embedding
    database.execute("
UPDATE omdb.movies SET movie_embedding = ? WHERE id = ?", embedding, id)

Follow the concise pseudocode from database extraction through text concatenation, model inference, and row updates. section 8.3.1

How Just Use Postgres! covers it

How deep it goes
Explains input preparation, vector storage, cosine-distance retrieval, and limitations, but stops short of model internals.
Examples
Demonstrates movie-description embeddings, Star Wars search results, and Python retrieval of three relevant movies.
What it assumes
Assumes basic Python and Postgres familiarity while providing a runnable Ollama-and-Jupyter path for experimentation.
What you can do after
Build and operate a local embedding pipeline that stores vectors and retrieves semantically similar movie records.
How it connects
Connects embeddings with pgvector, Postgres, cosine distance, vector similarity search, Ollama, LangChain, and RAG.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.