混合面包 API 访问

以下是所有可用的混合面包 API 过程的列表

名称 描述

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

创建可自定义的混合面包 API 调用

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

创建混合面包 API 调用以生成嵌入

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

表 1. 通用配置参数

描述

apiType

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

端点

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

apiVersion

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

路径

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

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

可选映射。请参见上面的 Configuration 表格

表 3. 结果
名称 描述

index

原始列表中的索引条目

text

原始列表中的文本行

embedding

浮点数/二进制的嵌入列表,或者在多个编码格式的情况下,嵌入浮点数/二进制列表的映射

生成嵌入调用
CALL apoc.ml.mixedbread.embedding(['Some Text'], $apiKey, {}) yield index, text, embedding;
表 4. 生成嵌入响应
index 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. 生成嵌入示例响应
index 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. 生成嵌入示例响应
index 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
}