Comments (9)
InsertParam has tow methods to input data:
withFields(List<InsertParam.Field> fields) ------------------------ this is column-based data
withRows(List rows) -------------------------------- this is row-based data
For column-based data, currently it doesn't support inputting dynamic values. This is an enhancement we can implement in future versions.
This example shows how to use withRows() to input dynamic values:
from milvus-sdk-java.
Even we do the enhancement, it is inconvenient for users in some cases.
For example, assume we have a collection with id field, vector field and dynamic filed, if we want to insert some rows like this:
{"id": 1, "vector": [v1], "desc_1": 1}
{"id": 2, "vector": [v2], "desc_2": 2}
{"id": 3, "vector": [v3], "desc_3": 3}
{"id": 4, "vector": [v4], "desc_4": 4}
{"id": 5, "vector": [v5], "desc_5": 5}
......
{"id": N, "vector": [vN], "desc_N": N}
How to represent the rows in column-based data? The user needs to construct N lists to hold the data:
field("id"): [1, 2, 3, 4, 5, ...... ,N]
field("vector"): [v1, v2, v3, v4, v5, ...... ,vN]
field("desc_1"): [1, None, None, None, ......, None]
field("desc_2"): [None, 2, None, None, ......, None]
field("desc_3"): [None, None, 3, None, ......, None]
......
field("desc_N"): [None, None, None, None, ......, N]
from milvus-sdk-java.
Even we do the enhancement, it is inconvenient for users in some cases. For example, assume we have a collection with id field, vector field and dynamic filed, if we want to insert some rows like this:
{"id": 1, "vector": [v1], "desc_1": 1} {"id": 2, "vector": [v2], "desc_2": 2} {"id": 3, "vector": [v3], "desc_3": 3} {"id": 4, "vector": [v4], "desc_4": 4} {"id": 5, "vector": [v5], "desc_5": 5} ...... {"id": N, "vector": [vN], "desc_N": N}
How to represent the rows in column-based data? The user needs to construct N lists to hold the data:
field("id"): [1, 2, 3, 4, 5, ...... ,N] field("vector"): [v1, v2, v3, v4, v5, ...... ,vN] field("desc_1"): [1, None, None, None, ......, None] field("desc_2"): [None, 2, None, None, ......, None] field("desc_3"): [None, None, 3, None, ......, None] ...... field("desc_N"): [None, None, None, None, ......, N]
Thanks for your reply.
In my opinion, generally the column based insert/upsert should be more efficient than the row based, even though Milvus are using the same InsertRequest
as the underlying buffer, therefor that may be the reason Python can insert/upsert dynamic fields in columnar batch in Your Official Sample Code Pieces.
So I am confused why the columnar interfaces in JAVA would throw out the dynamic fields in quiet, rather than trying to construct JSON fields or throw an exception, as that to do in Python.
Thanks. :)
from milvus-sdk-java.
In fact, all the official sample code to insert dynamic values are row-based:
https://milvus.io/docs/dynamic_schema.md#Insert-dynamic-data
https://github.com/milvus-io/pymilvus/blob/c4a05a71c0b2a84463d747bbb86ec2b9eac32157/examples/dynamic_field.py#L47
Python sdk doesn't support insert dynamic values in column-based.
from milvus-sdk-java.
In fact, all the official sample code to insert dynamic values are row-based: https://milvus.io/docs/dynamic_schema.md#Insert-dynamic-data https://github.com/milvus-io/pymilvus/blob/c4a05a71c0b2a84463d747bbb86ec2b9eac32157/examples/dynamic_field.py#L47
Python sdk doesn't support insert dynamic values in column-based.
Whatever, it's worthy to implement this feature in Java sdk? I don't think it's a difficult thing, of which code could be completed in ParamUtil
:
private void checkAndSetColumnData(List<FieldType> fieldTypes, List<InsertParam.Field> fields,
boolean dynamicFieldEnabled) {
Set<String> fieldsFound = new HashSet<>();
// gen fieldData
// make sure the field order must be consisted with collection schema
for (FieldType fieldType : fieldTypes) {
boolean found = false;
for (InsertParam.Field field : fields) {
if (field.getName().equals(fieldType.getName())) {
if (fieldType.isAutoID()) {
String msg = "The primary key: " + fieldType.getName()
+ " is auto generated, no need to input.";
throw new ParamException(msg);
}
checkFieldData(fieldType, field);
found = true;
fieldsFound.add(field.getName());
this.addFieldsData(genFieldData(field.getName(), fieldType.getDataType(), field.getValues()));
break;
}
}
if (!found && !fieldType.isAutoID()) {
String msg = "The field: " + fieldType.getName() + " is not provided.";
throw new ParamException(msg);
}
}
// deal with dynamicField
if (dynamicFieldEnabled) {
List<InsertParam.Field> dynamicFields = fields.stream()
.filter(f -> !fieldsFound.contains(f.getName()) && !f.getValues().isEmpty())
.collect(ImmutableList.toImmutableList());
Optional<InsertParam.Field> firstDynamicField = dynamicFields.stream().findFirst();
if (firstDynamicField.isPresent()) {
io.milvus.param.ParamUtils.InsertDataInfo insertDynamicDataInfo =
io.milvus.param.ParamUtils.InsertDataInfo.builder()
.dataType(DataType.JSON)
.data(new LinkedList<>())
.build();
int dynamicFieldDataSize = firstDynamicField.get().getValues().size();
for (int i = 0; i < dynamicFieldDataSize; i++) {
JSONObject jsonObject = new JSONObject();
for (InsertParam.Field f : dynamicFields) {
jsonObject.put(f.getName(), f.getValues().get(i));
}
insertDynamicDataInfo.getData().add(jsonObject);
}
this.addFieldsData(genFieldData(
insertDynamicDataInfo.getFieldName(), DataType.JSON, insertDynamicDataInfo.getData(), true));
}
}
}
from milvus-sdk-java.
any interest in contributing one
from milvus-sdk-java.
Let me think about it.
from milvus-sdk-java.
I submit a pr to support inserting dynamic values by column-based fields.
#674
After this commit is merged, user can insert dynamic values like this:
List<JSONObject> dynamics = new ArrayList<>();
for (long i = 0L; i < rowCount; ++i) {
JSONObject dynamic = new JSONObject();
dynamic.put("any_key", i);
dynamic.put("dynamic_key", true);
dynamics.add(dynamic);
}
List<InsertParam.Field> fieldsInsert = new ArrayList<>();
fieldsInsert.add(new InsertParam.Field(field1Name, ids));
fieldsInsert.add(new InsertParam.Field(field2Name, vectors));
fieldsInsert.add(new InsertParam.Field(Constant.DYNAMIC_FIELD_NAME, dynamics));
InsertParam insertColumnsParam = InsertParam.newBuilder()
.withCollectionName(CollectionName)
.withFields(fieldsInsert)
.build();
from milvus-sdk-java.
Fixed in java sdk v2.3.2 and this version has been released, close this issue.
from milvus-sdk-java.
Related Issues (20)
- some partitions [aaaa] of collection vvvv has been loaded into QueryNode, please release partitions firstly[LoadParameterMismatched] HOT 1
- set vector less than 1024 error HOT 5
- A connection error occurs after TLS authentication is enabled HOT 5
- [chore] update dependancy on grpc-netty HOT 4
- The latest (milvus-sdk-java:2.3.3) is flagged with several security vulnerabilities, all due to an outdated GRPC stack (1.46.0) HOT 4
- Run faild:io.grpc.StatusRuntimeException: UNKNOWN HOT 6
- Error occurred after version upgrade HOT 10
- [BUG]: Compatibility issue--Create index repeatedly,return error:‘ CreateIndexRequest RPC failed! io.grpc.StatusRuntimeException: CANCELLED: Failed to read message.’ HOT 2
- [BUG]: Compatibility issue--Flush retrun:'FlushRequest RPC failed!io.grpc.StatusRuntimeException: CANCELLED: Failed to read message.' HOT 2
- [Proposal] Changing log level to capture requestParam HOT 1
- loadCollection and releaseCollection ,Can resource isolation be ensured when calling multiple threads simultaneously HOT 2
- Scalar Field Index Type Selection
- Create index parameters problem for scalar HOT 3
- How to know collection had loaded via SDK? HOT 1
- How to truncate all collection data HOT 2
- How to set default values for scalar fields HOT 2
- Does it support transactions HOT 1
- 2.3版本sdk和xxxjob有jar包冲突 HOT 9
- ANN 查询数据 id返回值错误 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from milvus-sdk-java.