Mixedbread API 访问

以下是所有可用的 Mixedbread API 存储过程列表

名称 描述

apoc.ml.mixedbread.custom(body, $config)

用于创建可定制的 Mixedbread API 调用

apoc.ml.mixedbread.embedding(texts, $config)

用于创建生成嵌入的 Mixedbread API 调用

$config 参数与要传递给 http 请求的有效负载一致,并且还包含以下配置键。

表 1. 通用配置参数

描述

apiType

类似于 apoc.ml.openai.type APOC 配置

endpoint

类似于 apoc.ml.openai.url APOC 配置

apiVersion

类似于 apoc.ml.azure.api.version APOC 配置

path

用于定制添加到基本 URL(由 endpoint 配置定义)的 URL 部分。默认情况下,apoc.ml.openai.embeddingapoc.ml.openai.completionapoc.ml.openai.chat 存储过程分别对应 /embeddings/completions/chat/completions

jsonPath

用于定制响应的 JSONPath。对于 apoc.ml.openai.chatapoc.ml.openai.completion 存储过程,默认值为 $;对于 apoc.ml.openai.embedding 存储过程,默认值为 $.data

由于嵌入是 OpenAI 嵌入的一个超集,它们在底层利用了 apoc.ml.openai.* 存储过程,因此我们也可以创建 APOC 配置 apoc.ml.openai.url 来代替 endpoint 配置。

生成嵌入 API

此存储过程 apoc.ml.mixedbread.embedding 可以接受文本字符串列表,并为每个字符串返回一行,其中嵌入数据是一个 1536 元素的向量。它使用 /embeddings/create API,该 API 在此处有文档说明

额外配置会传递给 API,使用的默认模型是 mxbai-embed-large-v1

表 2. 参数
名称 描述

texts

文本字符串列表

apiKey

OpenAI API 密钥

configuration

可选映射。参见上面的配置

表 3. 结果
名称 描述

索引

原始列表中的索引条目

text

原始列表中的文本行

embedding

浮点数/二进制嵌入列表,或者在有多个 encoding_format 的情况下,是浮点数/二进制嵌入列表的映射

生成嵌入调用
CALL apoc.ml.mixedbread.embedding(['Some Text'], $apiKey, {}) yield index, text, embedding;
表 4. 生成嵌入响应
索引 text embedding

0

"Some Text"

[-0.0065358975, -7.9563365E-4, …​. -0.010693862, -0.005087272]

使用自定义嵌入维度和模型生成嵌入调用
CALL apoc.ml.mixedbread.embedding(['Some Text', 'Other Text'],
    $apiKey,
    {model: 'mxbai-embed-2d-large-v1', dimensions: 4}
)
表 5. 生成嵌入示例响应
索引 text embedding

0

"Some Text"

[0.019943237, -0.08843994, 0.068603516, 0.034942627]

1

"Other Text"

[0.011482239, -0.09069824, 0.05331421, 0.034088135]

使用自定义嵌入维度、模型和编码格式生成嵌入调用
CALL apoc.ml.mixedbread.embedding(['Some Text', 'garpez'],
    $apiKey,
    {encoding_format: ["float", "binary", "ubinary", "int8", "uint8", "base64"]}
)
表 6. 生成嵌入示例响应
索引 text embedding

0

"Some Text"

{binary: <binaryResult>, ubinary: <ubinaryResult>, int8: <int8Result>, uint8: <uint8Result>, base64: <base64Result>, float: <floatResult>}

0

"garpez"

{binary: <binaryResult>, ubinary: <ubinaryResult>, int8: <int8Result>, uint8: <uint8Result>, base64: <base64Result>, float: <floatResult>}

自定义 API

通过 apoc.ml.mixedbread.custom,我们可以创建一个可定制的 Mixedbread API 请求,返回一个通用的对象流。

例如,我们可以使用重新排名 API

重新排名 API 调用
CALL apoc.ml.mixedbread.custom($apiKey,
    {
        endpoint: "https://api.mixedbread.ai/v1/reranking",
        model: "mixedbread-ai/mxbai-rerank-large-v1",
        query: "Who is the author of To Kill a Mockingbird?",
        top_k: 3,
        input: [
            "To Kill a Mockingbird is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.",
                    "The novel Moby-Dick was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.",
                    "Harper Lee, an American novelist widely known for her novel To Kill a Mockingbird, was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.",
                    "Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.",
                    "The Harry Potter series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.",
                    "The Great Gatsby, a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan."
        ]
    }
)
表 7. 生成嵌入示例响应
value
{
  "model": "mixedbread-ai/mxbai-rerank-large-v1",
  "return_input": false,
  "data": [
    {
      "index": 0,
      "score": 0.9980469,
      "object": "text_document"
    },
    {
      "index": 2,
      "score": 0.9980469,
      "object": "text_document"
    },
    {
      "index": 3,
      "score": 0.06915283,
      "object": "text_document"
    }
  ],
  "usage": {
    "total_tokens": 302,
    "prompt_tokens": 302
  },
  "object": "list",
  "top_k": 3
}
© . All rights reserved.