Mastra 框架中接入 Qdrant 向量库的接口用法

Mastra 是用于快速构建 AI 应用的 TypeScript 框架,提供工作流、智能体、RAG 等基础能力。其 RAG 模块可将 Qdrant 作为向量存储,通过构造参数连接实例,并用索引、写入、查询等方法完成检索流程。

## 马斯特拉 [马斯特拉](<https://mastra.ai/>) 是快速构建 AI 应用程序和特性的 Typescript 框架。 它为您提供了您所需要的原始的一组: 工作流程、 代理、 RAG 、 集成、 同步和 eval 。 您可以在您的本地机器上运行 Mastra, 或者部署到一个没有服务器的云中 。 Qdrant 可作为 Mastra 节点的矢量存储器,用于增强具有检索能力的应用程序. ## 设置 ```bash npm install @mastra/core ``` ## 使用量 ```typescript 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 }); ``` ## 构造器选项 | 名称 | 类型 | 说明 | | --- | --- | --- | | `url` | `string` | Qdrant 实例中的 REST URL. 例如 https://xyz-example.eu-central.aws.cloud.qdrant.io:6333 维基语录链接:名人名言 - 文学作品 - 谚语 - 谚语 - 谚语 - 谚语 - 谚语 - 谚语 - 谚语 | | `apiKey` | `string` | 可选 Qdrant API 密钥 | | `https` | `boolean` | 设置连接时是否使用 TLS。 建议 。 | ## 方法 ### `createIndex()` | 名称 | 类型 | 说明 | 默认值 | | --- | --- | --- | --- | | `indexName` | `string` | 要创建的索引名称 | | | `dimension` | `number` | 矢量尺寸 | | | `metric` | `string` | 相似性搜索的距离度量衡 | `cosine` | ### `upsert()` | 名称 | 类型 | 说明 | 默认值 | | --- | --- | --- | --- | | `vectors` | `number[][]` | 嵌入向量矩阵 | | | `metadata` | `Record<string, any>[]` | 每个矢量的元数据( 可选) | | | `namespace` | `string` | 可选的组织名称空间 | | ### `query()` | 名称 | 类型 | 说明 | 默认值 | | --- | --- | --- | --- | | `vector` | `number[]` | 查询向量以找到类似的向量 | | | `topK` | `number` | 返回的结果数量(可选) | `10` | | `filter` | `Record<string, any>` | 用于查询的元数据过滤器( 可选) | | ### `listIndexes()` 返回一系列索引名称作为字符串。 ### `describeIndex()` | 名称 | 类型 | 说明 | | --- | --- | --- | | `indexName` | `string` | 用于描述的索引名称 | #### 回返情况 ```typescript interface IndexStats { dimension: number; count: number; metric: "cosine" | "euclidean" | "dotproduct"; } ``` ### `deleteIndex()` | 名称 | 类型 | 说明 | | --- | --- | --- | | `indexName` | `string` | 要删除的索引名称 | ## 反应类型 以此格式返回查询结果 : ```typescript interface QueryResult { id: string; score: number; metadata: Record<string, any>; } ``` ## 进一步阅读 - [马斯特拉的例子](<https://github.com/mastra-ai/mastra/tree/main/examples>) - Mastra 文档

查看原始来源