Docker部署本地Pinecone Local 环境
Pinecone Local 是一个内存中的 Pinecone 仿真器,可用作 Docker 映像,Pinecone Local 不适合生产环境,仅用于开发测试。
Pinecone Local 是一个内存中的 Pinecone 仿真器,可用作 Docker 映像,Pinecone Local 不适合生产环境,仅用于开发测试。
局限性
Pinecone Local 具有以下限制:
在将 Pinecone Local 用于开发或测试之前,请务必查看其局限性。
例
以下示例假定您已启动没有索引的 Pinecone Local。它初始化客户端,创建密集索引和稀疏索引,将记录更新插入索引,检查其记录计数,并查询索引。
import { Pinecone } from '@pinecone-database/pinecone';
// Initialize a client.
// API key is required, but the value does not matter.
// Host and port of the Pinecone Local instance
// is required when starting without indexes.
const pc = new Pinecone({
apiKey: 'pclocal',
controllerHostUrl: 'http://localhost:5080'
});
// Create two indexes, one dense and one sparse
const denseIndexName = 'dense-index';
const sparseIndexName = 'sparse-index';
const denseIndexModel = await pc.createIndex({
name: denseIndexName,
vectorType: 'dense',
dimension: 2,
metric: 'cosine',
spec: {
serverless: {
cloud: 'aws',
region: 'us-east-1'
}
},
deletionProtection: 'disabled',
tags: { environment: 'development' },
});
console.log('Dense index model:', denseIndexModel);
const sparseIndexModel = await pc.createIndex({
name: sparseIndexName,
vectorType: 'sparse',
metric: 'dotproduct',
spec: {
serverless: {
cloud: 'aws',
region: 'us-east-1'
}
},
deletionProtection: 'disabled',
tags: { environment: 'development' },
});
console.log('\nSparse index model:', sparseIndexModel);
// Target each index
const denseIndexHost = (await pc.describeIndex(denseIndexName)).host;
const denseIndex = await pc.index(denseIndexName, 'http://' + denseIndexHost);
const sparseIndexHost = (await pc.describeIndex(sparseIndexName)).host;
const sparseIndex = await pc.index(sparseIndexName, 'http://' + sparseIndexHost);
// Upsert records into the dense index
await denseIndex.namespace('example-namespace').upsert([
{
id: 'vec1',
values: [1.0, -2.5],
metadata: { genre: 'drama' },
},
{
id: 'vec2',
values: [3.0, -2.0],
metadata: { genre: 'documentary' },
},
{
id: 'vec3',
values: [0.5, -1.5],
metadata: { genre: 'documentary' },
}
]);
// Upsert records into the sparse index
await sparseIndex.namespace('example-namespace').upsert([
{
id: 'vec1',
sparseValues: {
indices: [822745112, 1009084850, 1221765879, 1408993854, 1504846510, 1596856843, 1640781426, 1656251611, 1807131503, 2543655733, 2902766088, 2909307736, 3246437992, 3517203014, 3590924191],
values: [1.7958984, 0.41577148, 2.828125, 2.8027344, 2.8691406, 1.6533203, 5.3671875, 1.3046875, 0.49780273, 0.5722656, 2.71875, 3.0820312, 2.5019531, 4.4414062, 3.3554688]
},
metadata: {
chunk_text: 'AAPL reported a year-over-year revenue increase, expecting stronger Q3 demand for its flagship phones.',
category: 'technology',
quarter: 'Q3'
}
},
{
id: 'vec2',
sparseValues: {
indices: [131900689, 592326839, 710158994, 838729363, 1304885087, 1640781426, 1690623792, 1807131503, 2066971792, 2428553208, 2548600401, 2577534050, 3162218338, 3319279674, 3343062801, 3476647774, 3485013322, 3517203014, 4283091697],
values: [0.4362793, 3.3457031, 2.7714844, 3.0273438, 3.3164062, 5.6015625, 2.4863281, 0.38134766, 1.25, 2.9609375, 0.34179688, 1.4306641, 0.34375, 3.3613281, 1.4404297, 2.2558594, 2.2597656, 4.8710938, 0.5605469]
},
metadata: {
chunk_text: "Analysts suggest that AAPL's upcoming Q4 product launch event might solidify its position in the premium smartphone market.",
category: 'technology',
quarter: 'Q4'
}
},
{
id: 'vec3',
sparseValues: {
indices: [8661920, 350356213, 391213188, 554637446, 1024951234, 1640781426, 1780689102, 1799010313, 2194093370, 2632344667, 2641553256, 2779594451, 3517203014, 3543799498, 3837503950, 4283091697],
values: [2.6875, 4.2929688, 3.609375, 3.0722656, 2.1152344, 5.78125, 3.7460938, 3.7363281, 1.2695312, 3.4824219, 0.7207031, 0.0826416, 4.671875, 3.7011719, 2.796875, 0.61621094]
},
metadata: {
chunk_text: "AAPL's strategic Q3 partnerships with semiconductor suppliers could mitigate component risks and stabilize iPhone production",
category: 'technology',
quarter: 'Q3'
}
}
]);
// Check the number of records in each index
console.log('\nDense index stats:', await denseIndex.describeIndexStats());
console.log('\nSparse index stats:', await sparseIndex.describeIndexStats());
// Query the dense index with a metadata filter
const denseQueryResponse = await denseIndex.namespace('example-namespace').query({
vector: [3.0, -2.0],
filter: {
'genre': {'$eq': 'documentary'}
},
topK: 1,
includeValues: false,
includeMetadata: true,
});
console.log('\nDense query response:', denseQueryResponse);
const sparseQueryResponse = await sparseIndex.namespace('example-namespace').query({
sparseVector: {
indices: [767227209, 1640781426, 1690623792, 2021799277, 2152645940, 2295025838, 2443437770, 2779594451, 2956155693, 3476647774, 3818127854, 4283091697],
values: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
},
topK: 1,
includeValues: false,
includeMetadata: true
});
console.log('\nSparse query response:', sparseQueryResponse);
// Delete the index
await pc.deleteIndex(denseIndexName);
await pc.deleteIndex(sparseIndexName);
- Pinecone Local 仅在 Docker 中可用。
- Pinecone Local 是内存中仿真器,不适合用于生产。加载到 Pinecone Local 中的记录在停止后不会保留。
- Pinecone Local 不对客户端请求进行身份验证。API 密钥将被忽略。
- 每个索引的最大记录数:100,000。
-
启动 Pinecone Local
您可以将 Pinecone Local 配置为索引仿真器或数据库仿真器:
-
索引模拟器 - 此方法使用 Docker 映像在启动时创建和配置索引。当您想要快速尝试读取和写入数据而无需管理索引生命周期时,建议使用此方法。
pinecone-index使用索引仿真时,您只能将数据读取和写入启动时创建的索引。您不能创建新索引、列出索引或运行其他不涉及读取和写入数据的作。
-
数据库模拟器 - 此方法使用 Docker 映像更广泛地模拟 Pinecone 数据库。当您想要测试生产应用程序或手动创建和管理索引时,建议使用此选项。
pinecone-local - 索引模拟器
数据库模拟器
- Docker Compose
- Docker CLI
确保 Docker 已安装并在本地计算机上运行。
创建一个文件,为您希望 Pinecone Local 在启动时创建的每个索引定义一个服务,包括 Docker 镜像、运行索引的主机和端口以及其他索引详细信息:
docker-compose.yamlpinecone-indexservices: dense-index: image: ghcr.io/pinecone-io/pinecone-index:latest container_name: dense-index environment: PORT: 5081 INDEX_TYPE: serverless VECTOR_TYPE: dense DIMENSION: 2 METRIC: cosine ports: - "5081:5081" platform: linux/amd64 sparse-index: image: ghcr.io/pinecone-io/pinecone-index:latest container_name: sparse-index environment: PORT: 5082 INDEX_TYPE: serverless VECTOR_TYPE: sparse DIMENSION: 0 METRIC: dotproduct ports: - "5082:5082" platform: linux/amd64对于每个索引,根据需要更新环境变量:
-
PORT:指定要侦听的索引的端口号。 -
INDEX_TYPE:指定要创建的 Pinecone 索引的类型。接受的值: 或 .serverlesspod -
VECTOR_TYPE:指定要存储在索引中的向量类型。接受的值: 或 .densesparse只有无服务器索引支持 Sparse。 -
DIMENSION:指定要存储在索引中的向量的维度。对于稀疏索引,必须将其设置为 。0 -
METRIC:指定用于计算索引中向量之间相似度的距离度量。密集索引的接受值: , , 或 .稀疏索引的可接受值: .cosineeuclideandotproductdotproduct
要启动 Pinecone Local,请运行以下命令:
docker compose up -d您将看到一条消息,其中包含有关每个索引的详细信息。
2. 开发应用- Docker Compose
- Docker CLI
确保 Docker 已安装并在本地计算机上运行。
创建一个文件,为 Pinecone Local 定义服务,包括 Docker 镜像、Pinecone Local 将在其上运行的主机和端口,以及可用于索引的端口范围:
docker-compose.yamlpinecone-localservices: pinecone: image: ghcr.io/pinecone-io/pinecone-local:latest environment: PORT: 5080 PINECONE_HOST: localhost ports: - "5080-5090:5080-5090" platform: linux/amd64要启动 Pinecone Local,请运行以下命令:
compose up -d您将看到一条消息,其中包含有关 Pinecone Local 实例的详细信息。
针对 Pinecone Local 运行代码与针对您的 Pinecone 账户运行代码类似,但有以下区别:
-
Pinecone Local 不对客户端请求进行身份验证。API 密钥将被忽略。
-
最新版本的 Pinecone Local 使用 Pinecone API 版本,需要 Python SDK 及以上版本、Node.js SDK 及以上版本、Java SDK 及以上版本、Go SDK 及以上版本、.NET SDK 及以上版本。
2025-01v6.xv5.xv4.xv3.xv3.x - 3. 停止 Pinecone Local
Pinecone Local 是一个内存中的仿真器。在 Pinecone Local 停止后,加载到 Pinecone Local 中的记录不会保留。
要停止和删除 Pinecone Local 的资源,请运行以下命令:
docker compose down
火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。
更多推荐

所有评论(0)