跳到正文

向量

托管向量存储(RAG):集合与 upsert/query/delete,默认自研 pgvector。

概览

基础路径: https://api.infrai.cc/v1/vector
鉴权头: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/vector capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/vector/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

方法

vector.collection.create

POST /v1/vector/collection/create

创建向量集合(命名空间):指定向量维度与距离度量,作为 RAG 向量的容器。默认自研 pgvector;免费管理操作。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。
dimensionnumber
必填
向量维度(创建时必填;须与写入的 embedding 维度一致)。
metric"cosine" | "euclidean" | "dotproduct"可选距离度量:cosine(默认)、euclidean 或 dotproduct。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

Collection { collection, dimension, metric, vector_count, state }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/vector/collection/create \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"collection": "...", "dimension": 0}'

vector.upsert

POST /v1/vector/upsert

向集合写入/更新向量(id+embedding+metadata)。ai.embed → vector.upsert 一条龙完成 RAG 入库。计费工作动作。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。
vectorsArray<{ id, embedding: number[], metadata? }>
必填
待写入的向量:每条包含 id、embedding(number[])及可选 metadata。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

UpsertResult { collection, upserted }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/vector/upsert \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"collection": "...", "vectors": []}'

vector.query

POST /v1/vector/query

对集合做近似最近邻(ANN)相似检索,返回 top-k 最近向量及分数与 metadata。计费工作动作。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。
embeddingnumber[]
必填
查询向量——返回与该点最近的若干向量。
top_knumber可选返回的最近邻数量(默认 10)。
filterRecord<string, unknown>可选相似检索前应用的可选 metadata 过滤条件。

返回

QueryResult { collection, matches: Array<{ id, score, metadata? }> }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/vector/query \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"collection": "...", "embedding": []}'

vector.collection.get

GET /v1/vector/collection/get

获取向量集合配置(维度、度量、向量数)。免费管理读。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。

返回

Collection { collection, dimension, metric, vector_count, state }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/vector/collection/get \
  -H "Authorization: Bearer $INFRAI_API_KEY"

vector.collection.list

GET /v1/vector/collection/list

列出账户的向量集合。免费管理读。

返回

{ collections: Collection[] }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/vector/collection/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

vector.collection.delete

DELETE /v1/vector/collection/delete

删除向量集合及其全部向量。免费管理(幂等)。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

CollectionDeleteResult { collection, deleted }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/vector/collection/delete \
  -H "Authorization: Bearer $INFRAI_API_KEY"

vector.delete

DELETE /v1/vector/delete

按 id 从集合删除指定向量。免费管理。

参数

名称类型必填说明
collectionstring
必填
集合(命名空间)名称。
idsstring[]
必填
要从集合中删除的向量 id。
idempotency_keystring可选可选去重 key;相同重试将返回同一结果。

返回

DeleteResult { collection, deleted }

示例

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/vector/delete \
  -H "Authorization: Bearer $INFRAI_API_KEY"

全部能力

本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。

能力端点说明
vector.collection.createPOST /v1/vector/collection/createCreate a vector collection (namespace) for an embedding dimension and distance metric — the container for RAG vectors. Self-hosted on pgvector by default; free management.
vector.collection.deleteDELETE /v1/vector/collection/deleteDelete a vector collection and all its vectors. Free management (idempotent).
vector.collection.getGET /v1/vector/collection/getFetch a vector collection's configuration (dimension, metric, vector count). Free management read.
vector.collection.listGET /v1/vector/collection/listList the account's vector collections. Free management read.
vector.deleteDELETE /v1/vector/deleteDelete specific vectors by id from a collection. Free management.
vector.queryPOST /v1/vector/queryRun an approximate nearest-neighbor (ANN) similarity search over a collection, returning the top-k closest vectors with scores and metadata. Billable work-action.
vector.upsertPOST /v1/vector/upsertInsert or update vectors (id + embedding + metadata) into a collection. Pair ai.embed → vector.upsert for one-stop RAG ingestion. Billable work-action.

完整示例

本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。

单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。

python
#!/usr/bin/env python3
"""Infrai · vector — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) vector.collection.create — POST /v1/vector/collection/create · Create a vector collection (namespace) for an embedding dimension and distance metric — the container for RAG vectors. Self-hosted on pgvector by default; free management.
r1 = show("vector.collection.create", infrai("POST", "/v1/vector/collection/create", {"collection":"docs","dimension":3,"metric":"cosine"}))

# 2) vector.upsert — POST /v1/vector/upsert · Insert or update vectors (id + embedding + metadata) into a collection. Pair ai.embed → vector.upsert for one-stop RAG ingestion. Billable work-action.
r2 = show("vector.upsert", infrai("POST", "/v1/vector/upsert", {"collection":"docs","vectors":[{"id":"a","embedding":[0.1,0.2,0.3],"metadata":{"title":"intro"}}]}))

# 3) vector.query — POST /v1/vector/query · Run an approximate nearest-neighbor (ANN) similarity search over a collection, returning the top-k closest vectors with scores and metadata. Billable work-action.
r3 = show("vector.query", infrai("POST", "/v1/vector/query", {"collection":"docs","embedding":[0.1,0.2,0.3],"top_k":3}))