api embed docs (#5282)

This commit is contained in:
royjhan 2024-07-22 13:37:08 -07:00 committed by GitHub
parent d835368eb8
commit c0648233f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1026,7 +1026,7 @@ If `stream` is set to `false`, then the response is a single JSON object:
## Generate Embeddings ## Generate Embeddings
```shell ```shell
POST /api/embeddings POST /api/embed
``` ```
Generate embeddings from a model Generate embeddings from a model
@ -1034,10 +1034,11 @@ Generate embeddings from a model
### Parameters ### Parameters
- `model`: name of model to generate embeddings from - `model`: name of model to generate embeddings from
- `prompt`: text to generate embeddings for - `input`: text or list of text to generate embeddings for
Advanced parameters: Advanced parameters:
- `truncate`: truncates the end of each input to fit within context length. Returns error if `false` and context length is exceeded. Defaults to `true`
- `options`: additional model parameters listed in the documentation for the [Modelfile](./modelfile.md#valid-parameters-and-values) such as `temperature` - `options`: additional model parameters listed in the documentation for the [Modelfile](./modelfile.md#valid-parameters-and-values) such as `temperature`
- `keep_alive`: controls how long the model will stay loaded into memory following the request (default: `5m`) - `keep_alive`: controls how long the model will stay loaded into memory following the request (default: `5m`)
@ -1046,9 +1047,9 @@ Advanced parameters:
#### Request #### Request
```shell ```shell
curl http://localhost:11434/api/embeddings -d '{ curl http://localhost:11434/api/embed -d '{
"model": "all-minilm", "model": "all-minilm",
"prompt": "Here is an article about llamas..." "input": "Why is the sky blue?"
}' }'
``` ```
@ -1056,10 +1057,35 @@ curl http://localhost:11434/api/embeddings -d '{
```json ```json
{ {
"embedding": [ "model": "all-minilm",
0.5670403838157654, 0.009260174818336964, 0.23178744316101074, -0.2916173040866852, -0.8924556970596313, "embeddings": [[
0.8785552978515625, -0.34576427936553955, 0.5742510557174683, -0.04222835972905159, -0.137906014919281 0.010071029, -0.0017594862, 0.05007221, 0.04692972, 0.054916814,
] 0.008599704, 0.105441414, -0.025878139, 0.12958129, 0.031952348
]]
}
```
#### Request (Multiple input)
```shell
curl http://localhost:11434/api/embed -d '{
"model": "all-minilm",
"input": ["Why is the sky blue?", "Why is the grass green?"]
}'
```
#### Response
```json
{
"model": "all-minilm",
"embeddings": [[
0.010071029, -0.0017594862, 0.05007221, 0.04692972, 0.054916814,
0.008599704, 0.105441414, -0.025878139, 0.12958129, 0.031952348
],[
-0.0098027075, 0.06042469, 0.025257962, -0.006364387, 0.07272725,
0.017194884, 0.09032035, -0.051705178, 0.09951512, 0.09072481
]]
} }
``` ```
@ -1106,3 +1132,45 @@ A single JSON object will be returned.
] ]
} }
``` ```
## Generate Embedding
> Note: this endpoint has been superseded by `/api/embed`
```shell
POST /api/embeddings
```
Generate embeddings from a model
### Parameters
- `model`: name of model to generate embeddings from
- `prompt`: text to generate embeddings for
Advanced parameters:
- `options`: additional model parameters listed in the documentation for the [Modelfile](./modelfile.md#valid-parameters-and-values) such as `temperature`
- `keep_alive`: controls how long the model will stay loaded into memory following the request (default: `5m`)
### Examples
#### Request
```shell
curl http://localhost:11434/api/embeddings -d '{
"model": "all-minilm",
"prompt": "Here is an article about llamas..."
}'
```
#### Response
```json
{
"embedding": [
0.5670403838157654, 0.009260174818336964, 0.23178744316101074, -0.2916173040866852, -0.8924556970596313,
0.8785552978515625, -0.34576427936553955, 0.5742510557174683, -0.04222835972905159, -0.137906014919281
]
}
```