Skip to main content

Text Embeddings

Text embeddings are a way to represent text as a vector of numbers.

Embeddings are frequently used in Retrieval Augmented Generation (RAG) applications.

Read on to learn how to generate Text Embeddings fully locally using LM Studio's embeddings server.

Getting Text Embeddings from LM Studio's Local Server

Starting in version 0.2.19, LM Studio includes a text embedding endpoint that allows you to generate embeddings.

The request and response format follow OpenAI's API format. Read about it here.

Example use-cases include RAG applications, code-search applications, and any other application that requires text embeddings.

Text Embeddings

How-To

LM Studio 0.2.19 or newer is required. Download the beta version from lmstudio.ai/beta-releases.html

  1. Head to the Local Server tab (<-> on the left) and start the server.
  2. Load a text embedding model by choosing it from Embedding Model Settings dropdown.
  3. Utilize the POST /v1/embeddings endpoint to get embeddings for your text.

Example request:

  • Assuming the server is listening on port 1234
  • Supported input types are string and string[] (array of strings)
curl http://localhost:1234/v1/embeddings \
-H "Content-Type: application/json" \
-d '{
"input": "Your text string goes here",
"model": "model-identifier-here"
}'

Example response:

{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
-0.005118194036185741,
-0.05910402536392212,
... truncated ...
-0.02389773353934288
],
"index": 0
}
],
"model": "nomic-ai/nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.Q5_K_M.gguf",
"usage": {
"prompt_tokens": 0,
"total_tokens": 0
}
}

Which embedding models are available?

Any BERT model in GGUF format is expected to work. If you're running into issues, please report a bug on the LM Studio Discord.

Search and download these through LM Studio's in-app model downloader.

What Are Text Embeddings, Really?

For further reading about embeddings, check out: