Mixedbread API 访问

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

名称 (name) description(描述)

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

用于创建可自定义的 Mixedbread API 调用

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

用于创建 Mixedbread API 调用以生成嵌入(embeddings)

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

表 1. 通用配置参数

键 (key)

description(描述)

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

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

生成嵌入 API (Generate Embeddings API)

apoc.ml.mixedbread.embedding 过程可以接收一个文本字符串列表,并将为每个字符串返回一行,其中包含 1536 元素向量形式的嵌入数据。它使用 /embeddings/create API,该 API 的文档在此处

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

表 2. 参数
名称 (name) description(描述)

texts

文本字符串列表

apiKey

OpenAI API 密钥

配置

可选映射。请参阅上方的“配置”表格

表 3. 结果
名称 (name) description(描述)

index

原始列表中的索引条目

文本 (text)

原始列表中的文本行

embedding

浮点数/二进制格式的嵌入列表,或者在存在多种 encoding_format 的情况下为浮点数/二进制格式的嵌入列表映射

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

0

"一些文本"

[-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

"一些文本"

[0.019943237, -0.08843994, 0.068603516, 0.034942627]

1

"其他文本"

[0.011482239, -0.09069824, 0.05331421, 0.034088135]

带有自定义嵌入维度、模型和 encoding_format 的生成嵌入调用
CALL apoc.ml.mixedbread.embedding(['Some Text', 'garpez'],
    $apiKey,
    {encoding_format: ["float", "binary", "ubinary", "int8", "uint8", "base64"]}
)
表 6. 生成嵌入示例响应
index 文本 (text) embedding

0

"一些文本"

{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 请求,返回一个通用的对象流。

例如,我们可以使用 重新排序(Reranking)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. 生成嵌入示例响应
{
  "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
}
© . This site is unofficial and not affiliated with Neo4j, Inc.