-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Camel-Milvus: create rag helpers to be used as beans #21994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
smongiar
wants to merge
1
commit into
apache:main
Choose a base branch
from
smongiar:add-milvus-rag-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+725
−128
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
...camel-milvus/src/main/java/org/apache/camel/component/milvus/rag/RAGCreateCollection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.milvus.rag; | ||
|
|
||
| import io.milvus.grpc.DataType; | ||
| import io.milvus.param.collection.CreateCollectionParam; | ||
| import io.milvus.param.collection.FieldType; | ||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.component.milvus.MilvusAction; | ||
| import org.apache.camel.component.milvus.MilvusHeaders; | ||
|
|
||
| public class RAGCreateCollection implements Processor { | ||
|
|
||
| private String collectionName = "rag_collection"; | ||
| private String collectionDescription = "RAG collection"; | ||
| private String idFieldName = "id"; | ||
| private String dimension = "768"; | ||
| private String textFieldName = "content"; | ||
| private String textFieldDataType = "VarChar"; | ||
| private String vectorFieldName = "embedding"; | ||
| private String textFieldMaxLength = "2048"; | ||
| private String additionalTextFields; | ||
|
|
||
| @Override | ||
| public void process(Exchange exchange) throws Exception { | ||
| int vectorDim = Integer.parseInt(dimension); | ||
| int maxLength = Integer.parseInt(textFieldMaxLength); | ||
| DataType textDataType = DataType.valueOf(textFieldDataType); | ||
|
|
||
| FieldType idField = FieldType.newBuilder() | ||
| .withName(idFieldName) | ||
| .withDataType(DataType.Int64) | ||
| .withPrimaryKey(true) | ||
| .withAutoID(true) | ||
| .build(); | ||
|
|
||
| FieldType.Builder textFieldBuilder = FieldType.newBuilder() | ||
| .withName(textFieldName) | ||
| .withDataType(textDataType); | ||
| if (textDataType == DataType.VarChar) { | ||
| textFieldBuilder.withMaxLength(maxLength); | ||
| } | ||
| FieldType textField = textFieldBuilder.build(); | ||
|
|
||
| FieldType vectorField = FieldType.newBuilder() | ||
| .withName(vectorFieldName) | ||
| .withDataType(DataType.FloatVector) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be configurable? |
||
| .withDimension(vectorDim) | ||
| .build(); | ||
|
|
||
| CreateCollectionParam.Builder builder = CreateCollectionParam.newBuilder() | ||
| .withCollectionName(collectionName) | ||
| .withDescription(collectionDescription) | ||
| .addFieldType(idField) | ||
| .addFieldType(textField); | ||
|
|
||
| if (additionalTextFields != null && !additionalTextFields.isBlank()) { | ||
| for (String fieldName : additionalTextFields.split(",")) { | ||
| String trimmed = fieldName.trim(); | ||
| if (!trimmed.isEmpty()) { | ||
| FieldType extraField = FieldType.newBuilder() | ||
| .withName(trimmed) | ||
| .withDataType(DataType.VarChar) | ||
| .withMaxLength(maxLength) | ||
| .build(); | ||
| builder.addFieldType(extraField); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| builder.addFieldType(vectorField); | ||
|
|
||
| exchange.getIn().setBody(builder.build()); | ||
| exchange.getIn().setHeader(MilvusHeaders.ACTION, MilvusAction.CREATE_COLLECTION); | ||
| } | ||
|
|
||
| public String getCollectionName() { | ||
| return collectionName; | ||
| } | ||
|
|
||
| public void setCollectionName(String collectionName) { | ||
| this.collectionName = collectionName; | ||
| } | ||
|
|
||
| public String getCollectionDescription() { | ||
| return collectionDescription; | ||
| } | ||
|
|
||
| public void setCollectionDescription(String collectionDescription) { | ||
| this.collectionDescription = collectionDescription; | ||
| } | ||
|
|
||
| public String getIdFieldName() { | ||
| return idFieldName; | ||
| } | ||
|
|
||
| public void setIdFieldName(String idFieldName) { | ||
| this.idFieldName = idFieldName; | ||
| } | ||
|
|
||
| public String getDimension() { | ||
| return dimension; | ||
| } | ||
|
|
||
| public void setDimension(String dimension) { | ||
| this.dimension = dimension; | ||
| } | ||
|
|
||
| public String getTextFieldName() { | ||
| return textFieldName; | ||
| } | ||
|
|
||
| public void setTextFieldName(String textFieldName) { | ||
| this.textFieldName = textFieldName; | ||
| } | ||
|
|
||
| public String getTextFieldDataType() { | ||
| return textFieldDataType; | ||
| } | ||
|
|
||
| public void setTextFieldDataType(String textFieldDataType) { | ||
| this.textFieldDataType = textFieldDataType; | ||
| } | ||
|
|
||
| public String getVectorFieldName() { | ||
| return vectorFieldName; | ||
| } | ||
|
|
||
| public void setVectorFieldName(String vectorFieldName) { | ||
| this.vectorFieldName = vectorFieldName; | ||
| } | ||
|
|
||
| public String getTextFieldMaxLength() { | ||
| return textFieldMaxLength; | ||
| } | ||
|
|
||
| public void setTextFieldMaxLength(String textFieldMaxLength) { | ||
| this.textFieldMaxLength = textFieldMaxLength; | ||
| } | ||
|
|
||
| public String getAdditionalTextFields() { | ||
| return additionalTextFields; | ||
| } | ||
|
|
||
| public void setAdditionalTextFields(String additionalTextFields) { | ||
| this.additionalTextFields = additionalTextFields; | ||
| } | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
...l-ai/camel-milvus/src/main/java/org/apache/camel/component/milvus/rag/RAGCreateIndex.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.milvus.rag; | ||
|
|
||
| import io.milvus.param.IndexType; | ||
| import io.milvus.param.MetricType; | ||
| import io.milvus.param.index.CreateIndexParam; | ||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.component.milvus.MilvusAction; | ||
| import org.apache.camel.component.milvus.MilvusHeaders; | ||
|
|
||
| public class RAGCreateIndex implements Processor { | ||
|
|
||
| private String collectionName = "rag_collection"; | ||
| private String vectorFieldName = "embedding"; | ||
| private String indexType = "IVF_FLAT"; | ||
| private String metricType = "COSINE"; | ||
| private String extraParam = "{\"nlist\": 128}"; | ||
|
|
||
| @Override | ||
| public void process(Exchange exchange) throws Exception { | ||
| IndexType idxType = IndexType.valueOf(indexType); | ||
| MetricType metric = MetricType.valueOf(metricType); | ||
|
|
||
| CreateIndexParam param = CreateIndexParam.newBuilder() | ||
| .withCollectionName(collectionName) | ||
| .withFieldName(vectorFieldName) | ||
| .withIndexType(idxType) | ||
| .withMetricType(metric) | ||
| .withExtraParam(extraParam) | ||
| .withSyncMode(Boolean.TRUE) | ||
| .build(); | ||
|
|
||
| exchange.getIn().setBody(param); | ||
| exchange.getIn().setHeader(MilvusHeaders.ACTION, MilvusAction.CREATE_INDEX); | ||
| } | ||
|
|
||
| public String getCollectionName() { | ||
| return collectionName; | ||
| } | ||
|
|
||
| public void setCollectionName(String collectionName) { | ||
| this.collectionName = collectionName; | ||
| } | ||
|
|
||
| public String getVectorFieldName() { | ||
| return vectorFieldName; | ||
| } | ||
|
|
||
| public void setVectorFieldName(String vectorFieldName) { | ||
| this.vectorFieldName = vectorFieldName; | ||
| } | ||
|
|
||
| public String getIndexType() { | ||
| return indexType; | ||
| } | ||
|
|
||
| public void setIndexType(String indexType) { | ||
| this.indexType = indexType; | ||
| } | ||
|
|
||
| public String getMetricType() { | ||
| return metricType; | ||
| } | ||
|
|
||
| public void setMetricType(String metricType) { | ||
| this.metricType = metricType; | ||
| } | ||
|
|
||
| public String getExtraParam() { | ||
| return extraParam; | ||
| } | ||
|
|
||
| public void setExtraParam(String extraParam) { | ||
| this.extraParam = extraParam; | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
.../camel-ai/camel-milvus/src/main/java/org/apache/camel/component/milvus/rag/RAGDelete.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.milvus.rag; | ||
|
|
||
| import io.milvus.param.dml.DeleteParam; | ||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.component.milvus.MilvusAction; | ||
| import org.apache.camel.component.milvus.MilvusHeaders; | ||
|
|
||
| public class RAGDelete implements Processor { | ||
|
|
||
| private String collectionName = "rag_collection"; | ||
| private String filter; | ||
|
|
||
| @Override | ||
| public void process(Exchange exchange) throws Exception { | ||
| DeleteParam.Builder builder = DeleteParam.newBuilder() | ||
| .withCollectionName(collectionName); | ||
|
|
||
| if (filter != null && !filter.isEmpty()) { | ||
| builder.withExpr(filter); | ||
| } | ||
|
|
||
| exchange.getIn().setBody(builder.build()); | ||
| exchange.getIn().setHeader(MilvusHeaders.ACTION, MilvusAction.DELETE); | ||
| } | ||
|
|
||
| public String getCollectionName() { | ||
| return collectionName; | ||
| } | ||
|
|
||
| public void setCollectionName(String collectionName) { | ||
| this.collectionName = collectionName; | ||
| } | ||
|
|
||
| public String getFilter() { | ||
| return filter; | ||
| } | ||
|
|
||
| public void setFilter(String filter) { | ||
| this.filter = filter; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are int/long types Strings?