> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Embedding Model

> Create semantic embeddings for code with our OpenAI-compatible API

<Warning>
  **Planned for deprecation.** The Embedding model will be removed in a future release. For code search, use [WarpGrep](/sdk/components/warp-grep/index) instead. WarpGrep is a search agent that handles retrieval, ranking, and file reading in one call, replacing the need to manage embeddings, vector databases, and reranking pipelines yourself.
</Warning>

# Overview

The Embedding API converts code and text into high-dimensional vectors that capture semantic meaning. Our latest `morph-embedding-v3` model delivers state-of-the-art performance on code retrieval tasks, enabling powerful search, clustering, and similarity operations for code-related applications.

## Endpoint Reference

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  # Initialize the OpenAI client with Morph's API endpoint
  client = OpenAI(
      api_key="your-morph-api-key",
      base_url="https://api.morphllm.com/v1"
  )

  def get_embeddings(text: str) -> list[float]:
      response = client.embeddings.create(
          model="morph-embedding-v3",
          input=text
      )
      return response.data[0].embedding

  # Example: Get embeddings for code chunks
  def embed_code_chunks(code_chunks: list[str]) -> list[dict]:
      results = []

      for chunk in code_chunks:
          embedding = get_embeddings(chunk)
          results.append({
              "text": chunk,
              "embedding": embedding
          })

      return results

  # Store these embeddings in a vector database of your choice
  ```

  ```javascript JavaScript theme={null}
  import { OpenAI } from "openai";

  const client = new OpenAI({
    apiKey: "your-morph-api-key",
    baseURL: "https://api.morphllm.com/v1",
  });

  async function getEmbeddings(text) {
    const response = await client.embeddings.create({
      model: "morph-embedding-v3",
      input: text,
    });

    return response.data[0].embedding;
  }

  // Example: Get embeddings for code chunks
  async function embedCodeChunks(codeChunks) {
    const results = [];

    for (const chunk of codeChunks) {
      const embedding = await getEmbeddings(chunk);
      results.push({
        text: chunk,
        embedding: embedding,
      });
    }

    return results;
  }

  // Example usage
  const codeChunks = [
    "function calculateSum(a, b) { return a + b; }",
    "class UserRepository { constructor(database) { this.db = database; } }",
  ];

  embedCodeChunks(codeChunks).then((results) => console.log(results));
  ```

  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.morphllm.com/v1/embeddings \
    --header 'Authorization: Bearer your-morph-api-key' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "morph-embedding-v3",
      "input": "Your code or text to embed"
    }'
  ```
</CodeGroup>

## Parameters

| Parameter         | Type            | Required | Description                                                                                              |
| ----------------- | --------------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `model`           | string          | Yes      | The model ID to use for embedding generation. Use `morph-embedding-v3` (latest) or `morph-embedding-v3`. |
| `input`           | string or array | Yes      | The text to generate embeddings for. Can be a string or an array of strings.                             |
| `encoding_format` | string          | No       | The format in which the embeddings are returned. Options are `float` and `base64`. Default is `float`.   |

## Response Format

```json theme={null}
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [0.0023064255, -0.009327292, ...],
      "index": 0
    }
  ],
  "model": "morph-embedding-v3",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}
```

## Features

### morph-embedding-v3 (Latest)

* **State-of-the-Art Performance**: Achieves SoTA results across all coding benchmarks for accuracy:speed ratio - no embedding model comes close
* **1024 Dimensions**: Optimal dimensionality for rich semantic representation while maintaining efficiency
* **Unmatched Speed**: Fastest inference in the market while delivering superior accuracy on code retrieval tasks
* **Enhanced Code Understanding**: Improved semantic understanding of code structure and intent
* **Better Cross-Language Support**: Superior understanding of relationships between different programming languages
* **Improved Context Handling**: Better performance on longer code snippets and complex codebases

### Core Features (All Models)

* **Code Optimized**: Specially trained to understand programming languages and code semantics
* **High Dimensionality**: Creates rich embeddings that capture nuanced relationships between code concepts
* **Language Support**: Works with all major programming languages including Python, JavaScript, Java, Go, and more
* **Contextual Understanding**: Captures semantic meanings rather than just syntactic similarities
* **Batch Processing**: Efficiently processes multiple inputs in a single API call

## Common Use Cases

* **Semantic Code Search**: Create powerful code search systems that understand intent
* **Similar Code Detection**: Find similar implementations or potential code duplications
* **Code Clustering**: Group related code snippets for organization or analysis
* **Relevance Ranking**: Rank code snippets by relevance to a query
* **Concept Tagging**: Automatically tag code with relevant concepts or categories
