Skip to content

Commit

Permalink
Revert "Fix search transformers"
Browse files Browse the repository at this point in the history
This reverts commit 2a14e0e.
  • Loading branch information
shanghaikid committed Apr 17, 2024
1 parent 2a14e0e commit c453140
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 67 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ Machine learning and neural networks often use half-precision data types, such a
> collection_name: COLLECTION_NAME,
> output_fields: ['id', 'vector'],
> limit: 5,
> inputTransformers: {
> [DataType.BFloat16Vector]: f32ArrayToBf16Bytes,
> },
> outputTransformers: {
> transformers: {
> [DataType.BFloat16Vector]: bf16BytesToF32Array,
> },
> });
Expand Down
7 changes: 3 additions & 4 deletions milvus/grpc/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Data extends Collection {
* @param {string} data.collection_name - The name of the collection.
* @param {string} [data.partition_name] - The name of the partition (optional).
* @param {{ [x: string]: any }[]} data.data - The data to be inserted. If the field type is binary, the vector data length needs to be dimension / 8.
* @param {InputTransformers} data.transformers - The transformers for bf16 or f16 data, it accept an f32 array, it should output f16 or bf16 bytes (optional)
* @param {InsertTransformers} data.transformers - The transformers for bf16 or f16 data, it accept an f32 array, it should output f16 or bf16 bytes (optional)
* @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined.
*
* @returns {Promise<MutationResult>} The result of the operation.
Expand Down Expand Up @@ -441,8 +441,7 @@ export class Data extends Collection {
const { request, nq, round_decimal, isHybridSearch } = buildSearchRequest(
data,
collectionInfo,
this.milvusProto,
data.inputTransformers
this.milvusProto
);

// execute search
Expand All @@ -469,7 +468,7 @@ export class Data extends Collection {
// build final results array
const results = formatSearchResult(originSearchResult, {
round_decimal,
transformers: data.outputTransformers,
transformers: data.transformers,
});

return {
Expand Down
13 changes: 5 additions & 8 deletions milvus/types/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface CountReq extends collectionNameReq {
// because in javascript, there is no float16 and bfloat16 type
// we need to provide custom data transformer for these types
// milvus only accept bytes(buffer) for these types
export type InputTransformers = {
export type InsertTransformers = {
[DataType.BFloat16Vector]?: (bf16: BFloat16Vector) => Buffer;
[DataType.Float16Vector]?: (f16: Float16Vector) => Buffer;
};
Expand All @@ -107,7 +107,7 @@ export interface InsertReq extends collectionNameReq {
data?: RowData[]; // data to insert
fields_data?: RowData[]; // alias for data
hash_keys?: Number[]; // user can generate hash value depend on primarykey value
transformers?: InputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
transformers?: InsertTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
}

export interface DeleteEntitiesReq extends collectionNameReq {
Expand Down Expand Up @@ -281,8 +281,7 @@ export interface SearchReq extends collectionNameReq {
vector_type: DataType.BinaryVector | DataType.FloatVector; // vector field type
nq?: number; // number of query vectors
consistency_level?: ConsistencyLevelEnum; // consistency level
inputTransformers?: InputTransformers;
outputTransformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
transformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
}

// simplified search api parameter type
Expand All @@ -304,8 +303,7 @@ export interface SearchSimpleReq extends collectionNameReq {
ignore_growing?: boolean; // ignore growing
group_by_field?: string; // group by field
round_decimal?: number; // round decimal
inputTransformers?: InputTransformers;
outputTransformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
transformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
}

export type HybridSearchSingleReq = Pick<
Expand All @@ -315,8 +313,7 @@ export type HybridSearchSingleReq = Pick<
data: VectorTypes[] | VectorTypes; // vector to search
expr?: string; // filter expression
params?: keyValueObj; // extra search parameters
inputTransformers?: InputTransformers;
outputTransformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
transformers?: OutputTransformers; // provide custom data transformer for specific data type like bf16 or f16 vectors
};

// rerank strategy and parameters
Expand Down
20 changes: 3 additions & 17 deletions milvus/utils/Bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SparseVectorCSR,
SparseVectorCOO,
BFloat16Vector,
InputTransformers,
} from '..';

/**
Expand Down Expand Up @@ -253,8 +252,7 @@ export const bytesToSparseRow = (bufferData: Buffer): SparseFloatVector => {
export const buildPlaceholderGroupBytes = (
milvusProto: Root,
vectors: VectorTypes[],
vectorDataType: DataType,
transformers?: InputTransformers
vectorDataType: DataType
) => {
// create placeholder_group value
let bytes;
Expand All @@ -267,22 +265,10 @@ export const buildPlaceholderGroupBytes = (
bytes = vectors.map(v => f32ArrayToBinaryBytes(v as BinaryVector));
break;
case DataType.BFloat16Vector:
const bf16Transformer =
transformers && transformers[DataType.BFloat16Vector];
if (bf16Transformer) {
bytes = vectors.map(v => bf16Transformer(v as BFloat16Vector));
break;
}
bytes = vectors.map(v => v);
bytes = vectors.map(v => f32ArrayToBf16Bytes(v as BFloat16Vector));
break;
case DataType.Float16Vector:
const f16Transformer =
transformers && transformers[DataType.Float16Vector];
if (f16Transformer) {
bytes = vectors.map(v => f16Transformer(v as Float16Vector));
break;
}
bytes = vectors.map(v => v);
bytes = vectors.map(v => f32ArrayToF16Bytes(v as Float16Vector));
break;
case DataType.SparseFloatVector:
bytes = vectors.map(v => sparseToBytes(v as SparseFloatVector));
Expand Down
10 changes: 4 additions & 6 deletions milvus/utils/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
Float16Vector,
BFloat16Vector,
getSparseFloatVectorType,
InputTransformers,
InsertTransformers,
OutputTransformers,
} from '../';

Expand Down Expand Up @@ -542,7 +542,7 @@ export const getAuthString = (data: {
export const buildFieldData = (
rowData: RowData,
field: Field,
transformers?: InputTransformers
transformers?: InsertTransformers
): FieldData => {
const { type, elementType, name } = field;
switch (DataTypeMap[type]) {
Expand Down Expand Up @@ -662,8 +662,7 @@ export const convertRerankParams = (rerank: RerankerObj) => {
export const buildSearchRequest = (
data: SearchReq | SearchSimpleReq | HybridSearchReq,
collectionInfo: DescribeCollectionResponse,
milvusProto: Root,
transformers?: InputTransformers
milvusProto: Root
) => {
// type cast
const searchReq = data as SearchReq;
Expand Down Expand Up @@ -743,8 +742,7 @@ export const buildSearchRequest = (
placeholder_group: buildPlaceholderGroupBytes(
milvusProto,
searchingVector as VectorTypes[],
field.dataType!,
transformers
field.dataType!
),
search_params: parseToKeyValue(
searchReq.search_params || buildSearchParams(req, name)
Expand Down
8 changes: 1 addition & 7 deletions test/grpc/BFloat16Vector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ describe(`BFloat16 vector API testing`, () => {
collection_name: COLLECTION_NAME,
output_fields: ['id', 'vector'],
limit: 5,
inputTransformers: {
[DataType.BFloat16Vector]: f32ArrayToBf16Bytes,
},
outputTransformers: {
transformers: {
[DataType.BFloat16Vector]: bf16BytesToF32Array,
},
});
Expand All @@ -151,9 +148,6 @@ describe(`BFloat16 vector API testing`, () => {
collection_name: COLLECTION_NAME,
output_fields: ['id', 'vector'],
limit: 5,
inputTransformers: {
[DataType.BFloat16Vector]: f32ArrayToBf16Bytes,
},
});

// console.log('search', search);
Expand Down
9 changes: 0 additions & 9 deletions test/grpc/Float16Vector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ describe(`Float16 vector API testing`, () => {
collection_name: COLLECTION_NAME,
output_fields: ['id', 'vector'],
limit: 5,
inputTransformers: {
[DataType.Float16Vector]: f32ArrayToF16Bytes,
},
outputTransformers: {
[DataType.Float16Vector]: f16BytesToF32Array,
},
});

// console.log('search', search);
Expand All @@ -145,9 +139,6 @@ describe(`Float16 vector API testing`, () => {
vector: [data[0].vector, data[1].vector],
collection_name: COLLECTION_NAME,
output_fields: ['id', 'vector'],
inputTransformers: {
[DataType.Float16Vector]: f32ArrayToF16Bytes,
},
limit: 5,
});

Expand Down
12 changes: 0 additions & 12 deletions test/grpc/MultipleVectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ describe(`Multiple vectors API testing`, () => {
collection_name: COLLECTION_NAME,
data: [1, 2, 3, 4],
anns_field: 'vector2',
inputTransformers: {
[DataType.Float16Vector]: f32ArrayToF16Bytes,
},
});

expect(searchF16.status.error_code).toEqual(ErrorCode.SUCCESS);
Expand Down Expand Up @@ -218,9 +215,6 @@ describe(`Multiple vectors API testing`, () => {
rerank: RRFRanker(),
limit: 5,
output_fields: ['id', 'vector2', 'vector3'],
inputTransformers: {
[DataType.Float16Vector]: f32ArrayToF16Bytes,
},
});

expect(search.status.error_code).toEqual(ErrorCode.SUCCESS);
Expand Down Expand Up @@ -265,12 +259,6 @@ describe(`Multiple vectors API testing`, () => {
},
],
limit: 5,
inputTransformers: {
[DataType.Float16Vector]: f32ArrayToF16Bytes,
},
outputTransformers: {
[DataType.Float16Vector]: f16BytesToF32Array,
},
});

expect(search.status.error_code).toEqual(ErrorCode.SUCCESS);
Expand Down

0 comments on commit c453140

Please sign in to comment.