Generating Embeddings

This page provides an overview of APIs related to generating embeddings.

Embeddings are generated as part of the standard processing pipeline using the View Embeddings server. To generate embeddings manually, call POST /v1.0/tenants/[tenant-guid]/embeddings/ on the View Embeddings server, which by default listens on port 8000.

An embeddings request includes the following properties:

  • EmbeddingsRule object Embedding rule object
    • EmbeddingsGenerator string name of the embeddings generator service (e.g. LCProxy)
    • EmbeddingsGeneratorUrl string URL of the embeddings generator endpoint
    • EmbeddingsGeneratorApiKey string API key used to authenticate with the embeddings generator
    • BatchSize number number of items to process in a single batch request
    • MaxGeneratorTasks number maximum number of concurrent generator tasks allowed
    • MaxRetries number number of times to retry a failed generation task
    • MaxFailures number number of allowed failures before halting further processing
  • Model string the model you wish to you for embeddings generation
  • ApiKey string the HuggingFace API key, if the model requires authentication and authorization
  • Contents array an array containing each of the contents for which embeddings should be generated

An example request is as follows:

{
    "EmbeddingsRule": {
        "EmbeddingsGenerator": "LCProxy",
        "EmbeddingsGeneratorUrl": "http://nginx-lcproxy:8000/",
        "EmbeddingsGeneratorApiKey": "default",
        "BatchSize": 16,
        "MaxGeneratorTasks": 16,
        "MaxRetries": 3,
        "MaxFailures": 3
    },
    "Model": "all-MiniLM-L6-v2",
    "ApiKey": "",
    "Contents": [
        "This is a sample chunk of text, hello!",
    ]
}
curl --location 'http://view.homedns.org:8000/v1.0/tenants/00000000-0000-0000-0000-000000000000/embeddings/' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "EmbeddingsRule": {
        "EmbeddingsGenerator": "LCProxy",
        "EmbeddingsGeneratorUrl": "http://nginx-lcproxy:8000/",
        "EmbeddingsGeneratorApiKey": "default",
        "BatchSize": 16,
        "MaxGeneratorTasks": 16,
        "MaxRetries": 3,
        "MaxFailures": 3
    },
    "Model": "all-MiniLM-L6-v2",
    "ApiKey": "",
    "Contents": [
        "This is a sample chunk of text, hello!",
    ]
}'
import { ViewEmbeddingsSdk } from "view-sdk";

  const api = new ViewEmbeddingsSdk(
  "http://localhost:8000/", //endpoint
  "<tenant-guid>", //tenant Id
  "default" //access token
);

const generateEmbeddings = async () => {
  try {
    const response = await api.generateEmbeddings({
      EmbeddingsRule: {
        EmbeddingsGenerator: "LCProxy",
        EmbeddingsGeneratorUrl: "http://nginx-lcproxy:8000/",
        EmbeddingsGeneratorApiKey: "default",
        BatchSize: 16,
        MaxGeneratorTasks: 16,
        MaxRetries: 3,
        MaxFailures: 3,
      },
      Model: "all-MiniLM-L6-v2",
      ApiKey: "",
      Contents: ["This is a sample chunk of text, hello!"],
    });
    console.log(response, "Generate embeddings response");
  } catch (err) {
    console.log("Error", err);
  }
};

generateEmbeddings();

The response is as shown below. The contents of the Embeddings array are ordered to match the input content.

{
    "Success": true,
    "StatusCode": 200,
    "BatchCount": 1,
    "SemanticCells": [],
    "ContentEmbeddings": [
        {
            "Content": "This is a sample chunk of text, hello!",
            "Embeddings": [
                -0.044824813,
                0.08454175,
                0.043137725,
                ...
            ]
        }
    ]
}