Skip to content

patonkikh/EmbeddingBattle

Repository files navigation

Embedding Battle

Compare two words side-by-side with local embedding models. Built for RAG prototyping — see cosine similarity, vector previews, and per-dimension diffs in one clean UI.

License: MIT React Vite LM Studio TypeScript


Preview

Embedding Battle UI — comparing cat vs dog with text-embedding-bge-m3

Two words in, embeddings out — cosine similarity and dimension-level diff at a glance.


What it does

Embedding Battle is a lightweight web app that connects to LM Studio and sends two text inputs to an embedding model one after another. It then:

  • displays both embedding vectors (preview + full JSON)
  • calculates cosine similarity — the standard metric for vector search in RAG
  • visualizes per-dimension differences (green = close, red = divergent)
  • gives a plain-English RAG relevance verdict (high / moderate / low)

No cloud API keys. Everything runs on your machine.


Quick start

Prerequisites

Tool Version Notes
Node.js 18+ Required to run the UI
LM Studio Latest Local embedding server
Embedding model GGUF e.g. nomic-embed-text, bge-m3

1. Clone the repository

git clone https://github.com/patonkikh/EmbeddingBattle.git
cd EmbeddingBattle

2. Install dependencies

npm install

3. Configure environment variables

Copy the example env file and edit it:

cp .env.example .env

Open .env and set your values:

# LM Studio local server URL (default port is 1234)
VITE_LM_STUDIO_URL=http://127.0.0.1:1234

# Comma-separated model IDs — must match names shown in LM Studio
VITE_EMBEDDING_MODELS=text-embedding-nomic-embed-text-v1.5,text-embedding-bge-m3

Note: This project does not require API keys or credentials. LM Studio accepts any placeholder key and runs fully offline. All configuration lives in .env — never commit your local .env file.

Variable Description Example
VITE_LM_STUDIO_URL Base URL of the LM Studio server http://127.0.0.1:1234
VITE_EMBEDDING_MODELS Model IDs for the dropdown (comma-separated) text-embedding-bge-m3

Use 127.0.0.1 instead of localhost if you hit connection issues on Windows (IPv6 mismatch).

4. Set up LM Studio

  1. Download & install LM Studio.
  2. Download an embedding model from the Discover tab, for example:
    • nomic-embed-text-v1.5
    • bge-m3
  3. Load the model in LM Studio (Developer / My Models → load into memory).
  4. Start the local server:
    • Open the Local Server tab (or Developer → Server)
    • Enable the server on port 1234
    • Confirm the model identifier matches your .env entry

Verify the server is running:

curl http://127.0.0.1:1234/v1/embeddings \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-bge-m3",
    "input": "hello world"
  }'

You should get a JSON response with an embedding array.

5. Run the app

npm run dev

Open the URL shown in the terminal (usually http://localhost:5173).

  1. Enter Word 1 and Word 2
  2. Pick a model from the dropdown
  3. Click Start

Production build

npm run build
npm run preview

The static build is output to dist/. Serve it with any static host; the dev proxy is only used during npm run dev.


How similarity is interpreted

Cosine similarity RAG verdict Meaning
≥ 85% High Likely relevant — would rank well in vector search
65–85% Moderate Possibly relevant — depends on your threshold
< 65% Low Unlikely to be retrieved as a match

Cosine similarity is the primary metric used by most vector databases (Pinecone, Chroma, Qdrant, pgvector, etc.) when retrieving documents for RAG.


Project structure

EmbeddingBattle/
├── docs/
│   └── screenshot.png      # UI preview for README
├── src/
│   ├── App.tsx             # Main layout & form
│   ├── components/
│   │   ├── EmbeddingPanel.tsx
│   │   └── SimilarityCard.tsx
│   └── lib/
│       ├── lmStudio.ts     # LM Studio API client
│       └── similarity.ts   # Cosine / euclidean metrics
├── .env.example            # Template for configuration
├── vite.config.ts          # Dev proxy → LM Studio
└── README.md

During development, browser requests go to /api/lm/embeddings and Vite proxies them to {VITE_LM_STUDIO_URL}/v1/embeddings.


Adding more models

  1. Download and load the model in LM Studio.
  2. Copy its model identifier from the LM Studio UI.
  3. Append it to VITE_EMBEDDING_MODELS in .env (comma-separated).
  4. Restart the dev server (Ctrl+Cnpm run dev).

Example:

VITE_EMBEDDING_MODELS=text-embedding-nomic-embed-text-v1.5,text-embedding-bge-m3,text-embedding-my-custom-model

Troubleshooting

Problem Fix
Connection refused Ensure LM Studio server is running on port 1234
Model not found Model ID in .env must exactly match LM Studio
Empty embedding response Load the embedding model into memory first
CORS errors Use npm run dev — the Vite proxy handles CORS
localhost fails on Windows Switch to 127.0.0.1 in .env

Tech stack

  • React 19 + TypeScript
  • Vite 6 with dev proxy
  • Tailwind CSS 4
  • LM Studio OpenAI-compatible /v1/embeddings API

Contributing

Issues and pull requests are welcome. For new embedding models, updating .env.example with a commented example is appreciated.


License

MIT © 2026 patonkikh


Tags
#embeddings  #rag  #lmstudio  #vectorsearch  #cosinesimilarity  #react  #vite  #typescript  #tailwindcss  #nomic  #bge-m3  #opensource  #machinelearning  #nlp  #localai

⭐ If this helped your RAG experiments, consider starring the repo!

About

Compare embedding models locally with LM Studio — cosine similarity UI for RAG workflows

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors