Mastra
Mastra 是一个 Typescript 框架,用于快速构建 AI 应用程序和功能。它提供了您所需的原语集:工作流、代理、RAG、集成、同步和评估。您可以在本地机器上运行 Mastra,也可以部署到无服务器云。
Qdrant 可作为 Mastra 节点中的向量存储,以增强应用程序的检索能力。
设置
用法
import { QdrantVector } from "@mastra/rag";
const qdrant = new QdrantVector({
url: "https://xyz-example.eu-central.aws.cloud.qdrant.io:6333"
apiKey: "<YOUR_API_KEY>",
https: true
});
构造函数选项
方法
createIndex()
| 名称 | 类型 | 描述 | 默认值 |
|---|
indexName | 字符串 | 要创建的索引名称 | |
dimension | 数字 | 向量维度大小 | |
metric | 字符串 | 用于相似性搜索的距离度量 | 余弦 |
upsert()
| 名称 | 类型 | 描述 | 默认值 |
|---|
vectors | number[][] | 嵌入向量数组 | |
metadata | Record<string, any>[] | 每个向量的元数据(可选) | |
namespace | 字符串 | 可选的组织命名空间 | |
query()
| 名称 | 类型 | 描述 | 默认值 |
|---|
vector | number[] | 用于查找相似向量的查询向量 | |
topK | 数字 | 要返回的结果数量(可选) | 10 |
filter | Record<string, any> | 查询的元数据过滤器(可选) | |
listIndexes()
返回一个包含索引名称的字符串数组。
describeIndex()
| 名称 | 类型 | 描述 |
|---|
indexName | 字符串 | 要描述的索引名称 |
返回
interface IndexStats {
dimension: number;
count: number;
metric: "cosine" | "euclidean" | "dotproduct";
}
deleteIndex()
| 名称 | 类型 | 描述 |
|---|
indexName | 字符串 | 要删除的索引名称 |
响应类型
查询结果以这种格式返回
interface QueryResult {
id: string;
score: number;
metadata: Record<string, any>;
}
延伸阅读