public static Tensor toBitTensor(IndexedTensor result, TensorType type, int nTokens) {
        if (type.valueType() != TensorType.Value.INT8)
            throw new IllegalArgumentException("Only a int8 tensor type can be the destination of bit packing");
        if(result.shape().length != 3)
            throw new IllegalArgumentException("Expected onnx result to have 3-dimensions [batch, sequence, dim]");

        int size = type.indexedSubtype().dimensions().size();
        if (size != 1)
            throw new IllegalArgumentException("Target indexed sub-type must have one dimension");
        int wantedDimensionality = type.indexedSubtype().dimensions().get(0).size().get().intValue();
        //Allow using the first n float dimensions to pack into int8
        int floatDimensionality = 8 * wantedDimensionality;
        int resultDimensionality = (int)result.shape()[2];
        if (floatDimensionality > resultDimensionality) {
            throw new IllegalArgumentException("Not possible to pack " + resultDimensionality +
                                               " + dimensions into " + wantedDimensionality + " dimensions");
        }
        Tensor.Builder builder = Tensor.Builder.of(type);
        for (int token = 0; token < nTokens; token++) {
            BitSet bitSet = new BitSet(8);
            int key = 0;
            for (int d = 0; d < floatDimensionality; d++) {
                var value = result.get(0, token, d); // batch, sequence token, dimension
                int bitIndex = 7 - (d % 8);
                if (value > 0.0) {
                    bitSet.set(bitIndex);
                } else {
                    bitSet.clear(bitIndex);
                }
                if ((d + 1) % 8 == 0) {
                    byte[] bytes = bitSet.toByteArray();
                    byte packed = (bytes.length == 0) ? 0 : bytes[0];
                    builder.cell(TensorAddress.of(token, key), packed);
                    key++;
                    bitSet = new BitSet(8);
                }
            }
        }
        return builder.build();
    }
Evaluate the embedding model if the result is not present in the context cache.

@param context the context accompanying the request
@param text the text that is embedded
@return the model output
model-integration/src/main/java/ai/vespa/embedding/ColBertEmbedder.java