Generate Embeddings
Generate embeddings for code
Overview
Morph provides an OpenAI-compatible API for generating embeddings from code and text. Morph embeddings are optimized to be state of the art for code, and are specifically made to be used on functional units like Syntax Tree Nodes (functions, classes, etc.) - not every N tokens. Use this in the Morph SDK to detect when files change, Syntax Tree parse, and re-embed automatically.
API Endpoint
Example Request
Input Format
The request accepts the following parameters:
Parameter | Type | Required | Description |
---|---|---|---|
model | string | Yes | The model ID to use for embedding generation. Use morph-embedding-v2 . |
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 . |
Batch Processing Example
cURL Example
Response Format
When multiple inputs are provided, the response includes embeddings for each input:
Usage with Vector Databases
Embeddings can be stored in vector databases for efficient similarity searching:
Authorizations
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Body
Embedding generation request
The body is of type object
.
Response
Embedding response
The response is of type object
.