无法在 Milvus 中存储嵌入:错误:插入失败:该集合中的某些字段不存在。 0

问题描述 投票:0回答:1

尝试向 milvus bd 集合添加一些嵌入,但遇到了上述错误。

代码:

const { MilvusClient, DataType } = require('@zilliz/milvus2-sdk-node');
const express = require('express');
const app = express();
app.use(express.json());

const client = new MilvusClient("localhost:19530");

let idCounter = 0;

async function main() {
try {
const collections = await client.showCollections();
console.log("List all collections:\n", collections);
} catch (error) {
console.error("Error listing collections:", error);
}
}

async function storeEmbeddings(filename, embeddings) {
try {
const collectionName = 'embedding_test_2';

    // Check if collection already exists
    const collectionsInfo = await client.showCollections();
    const existingCollections = collectionsInfo.collection_names || [];
    console.log('Existing collections:', existingCollections);

    if (!existingCollections.includes(collectionName)) {
        await client.createCollection({
            collection_name: collectionName,
            fields: [
                { name: "my_id", data_type: DataType.Int64, is_primary_key: true, auto_id: false }, // Ensure primary key is int64
                { name: "filename", data_type: DataType.VarChar, max_length: 256 }, // varchar type for strings
                { name: "embedding", data_type: DataType.FloatVector, dim: embeddings.length } // Correct field definition
            ],
        });
        console.log(`Collection ${collectionName} created`);
    } else {
        console.log(`Collection ${collectionName} already exists`);
    }

    // Logging field names and data to be inserted
    console.log('Inserting data:', {
        collection_name: collectionName,
        fields_data: [
            { name: "my_id", values: idCounter + 1 },
            { name: "filename", values: filename },
            { name: "embedding", values: [embeddings] }
        ]
    });

    // Log the embedding array
    console.log('Embedding array:', embeddings);

    await client.insert({
        collection_name: collectionName,
        fields_data: [
            { name: "my_id", values: [idCounter++] },
            { name: "filename", values: [filename] },
            { name: "embedding", values: [embeddings] }
        ]
    });

    console.log("Embeddings stored successfully in Milvus");
} catch (error) {
    console.error('Failed to store embeddings in Milvus:', error);
}
}

module.exports = {
storeEmbeddings,
main
};

错误:

无法在 Milvus 中存储嵌入:错误:插入失败:该集合中的某些字段不存在。 0 在/Users/razataiab/Desktop/custom-rag/node_modules/@zilliz/milvus2-sdk-node/dist/milvus/grpc/Data.js:195:31 在Array.forEach() 在/Users/razataiab/Desktop/custom-rag/node_modules/@zilliz/milvus2-sdk-node/dist/milvus/grpc/Data.js:192:28 在Array.forEach() 在 MilvusClient。 (/Users/razataiab/Desktop/custom-rag/node_modules/@zilliz/milvus2-sdk-node/dist/milvus/grpc/Data.js:184:30) 在 Generator.next() 处 已完成 (/Users/razataiab/Desktop/custom-rag/node_modules/@zilliz/milvus2-sdk-node/dist/milvus/grpc/Data.js:5:58) 在 process.processTicksAndRejections (节点:内部/进程/task_queues:95:5)

尝试向 milvus bd 集合添加一些嵌入,但遇到了上述错误。

vectorization embedding vector-database milvus
1个回答
0
投票

您应该在此处准备基于行的数据。像这样:

await client.insert({
  collection_name: collectionName,
  data: [
    { filename: 'some-file-name1',  embedding: [0.1,0.2,...]},
    { filename: 'some-file-name1',  embedding: [0.1,0.2,...]},
  ]
});

目前,Node sdk 接受基于行的文件,谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.