diff --git a/libs/langchain-community/src/vectorstores/milvus.ts b/libs/langchain-community/src/vectorstores/milvus.ts index d8844c31c2a2..d15fe0c0b6f7 100644 --- a/libs/langchain-community/src/vectorstores/milvus.ts +++ b/libs/langchain-community/src/vectorstores/milvus.ts @@ -573,7 +573,7 @@ export class Milvus extends VectorStore { }); desc.schema.fields.forEach((field) => { this.fields.push(field.name); - // Only remove autoID fields from this.fields if we're using autoId mode + // Remove autoID fields from this.fields if we're using autoId mode // When autoId is false, we need to include the primary field for upsert operations if (field.autoID && this.autoId) { const index = this.fields.indexOf(field.name); @@ -581,6 +581,14 @@ export class Milvus extends VectorStore { this.fields.splice(index, 1); } } + // Remove isFunctionOutput fields from this.fields if this field is calculated on server side + // When isFunctionOutput is false, we need to include this field for upsert operations + if (field.is_function_output) { + const index = this.fields.indexOf(field.name); + if (index !== -1) { + this.fields.splice(index, 1); + } + } if (field.is_primary_key) { this.primaryField = field.name; } diff --git a/libs/langchain-community/src/vectorstores/tests/milvus.test.ts b/libs/langchain-community/src/vectorstores/tests/milvus.test.ts index ee3c0e86d901..38fdc4c607f5 100644 --- a/libs/langchain-community/src/vectorstores/tests/milvus.test.ts +++ b/libs/langchain-community/src/vectorstores/tests/milvus.test.ts @@ -10,27 +10,38 @@ const fields = [ { name: "id", is_primary_key: true, + is_function_output: false, autoID: true, data_type: 21, }, { name: "text", is_primary_key: false, + is_function_output: false, autoID: false, data_type: 21, }, { name: "vector", is_primary_key: false, + is_function_output: false, autoID: false, data_type: 101, }, { name: "custom_field", is_primary_key: false, + is_function_output: false, autoID: false, data_type: 21, }, + { + name: "vector_calculated", + is_primary_key: false, + is_function_output: true, + autoID: false, + data_type: 104, + }, ]; // Mock successful responses