Amazon Nova 2 Multimodal Embeddings with Amazon S3 Vectors and AWS Java SDK - Part 2 Create and store text and image embeddings

Published: (January 19, 2026 at 11:05 AM EST)
4 min read
Source: Dev.to

Source: Dev.to

1. Maven dependencies

Add the following AWS SDK for Java modules to your pom.xml:

software.amazon.awssdk
bedrockruntime

software.amazon.awssdk
s3vectors

software.amazon.awssdk
s3

2. Business logic

The sample application’s core logic lives in the class AmazonNovaMultimodalEmbeddings.

2.1 Create & store text embeddings

private static void createAndStoreTextEmbeddings(String text, String key) throws Exception {
    Float[] embeddings = createTextEmbeddings(text, "GENERIC_INDEX");
    putVectors(embeddings, key);
}

2.2 Generate text embeddings

We build a JSON request (using a string template) that is later sent to Bedrock via InvokeModelRequest.

Key parameters

ParameterValue / Options
taskTypeSINGLE_EMBEDDING
embeddingPurposeGENERIC_INDEX (used for multimodal embeddings)
embeddingDimension384 (other supported sizes: 3072, 1024, 256)
textThe input string (truncated at the end)
private static Float[] createTextEmbeddings(String text, String embeddingPurpose) throws Exception {
    String request = """
        {
            "taskType": "SINGLE_EMBEDDING",
            "singleEmbeddingParams": {
                "embeddingPurpose": {{embeddingPurpose}},
                "embeddingDimension": {{dimension}},
                "text": {"truncationMode": "END", "value": {{text}}}
            }
        }
        """
        .replace("{{text}}", "\"" + text + "\"")
        .replace("{{dimension}}", String.valueOf(EMBEDDING_DIMENSION))
        .replace("{{embeddingPurpose}}", "\"" + embeddingPurpose + "\"");

    var eResponse = invokeBedrockModel(request);
    return eResponse.embeddings().getFirst().embedding();
}

Note: For the complete request/response schema, see the official Amazon Nova 2 documentation.

2.3 Invoke the Bedrock model

private static EmbeddingResponse invokeBedrockModel(String request) throws Exception {
    var imRequest = InvokeModelRequest.builder()
            .modelId(MODEL_ID)                                 // e.g. "amazon.nova-2-multimodal-embeddings-v1:0"
            .body(SdkBytes.fromUtf8String(request))
            .contentType("application/json")
            .accept("application/json")
            .build();

    var imResponse = BEDROCK_RUNTIME_CLIENT.invokeModel(imRequest);
    return MAPPER.readValue(imResponse.body().asUtf8String(), EmbeddingResponse.class);
}

BEDROCK_RUNTIME_CLIENT is a singleton BedrockRuntimeClient that you create elsewhere in the class.

3. Store embeddings in Amazon S3 Vectors

3.1 Create the vector bucket and index

private static final String VECTOR_BUCKET = "vk-vector-store";   // make this unique for your account
private static final String INDEX_NAME   = "embeddings";

private static void createS3VectorBucketAndIndex() {
    // 1️⃣ Create the vector bucket
    var createBucketReq = CreateVectorBucketRequest.builder()
            .vectorBucketName(VECTOR_BUCKET)
            .build();
    S3_VECTORS_CLIENT.createVectorBucket(createBucketReq);

    // 2️⃣ Create the index inside the bucket
    var createIndexReq = CreateIndexRequest.builder()
            .vectorBucketName(VECTOR_BUCKET)
            .indexName(INDEX_NAME)
            .dataType("float32")
            .dimension(EMBEDDING_DIMENSION)
            .distanceMetric("cosine")          // alternative: "euclidean"
            .build();
    S3_VECTORS_CLIENT.createIndex(createIndexReq);
}

After running the method you can see the bucket and index in the Amazon S3 Vector buckets console.

3.2 Put vectors into the index

private static void putVectors(Float[] embeddings, String key) {
    // Convert the float array into the VectorData structure expected by S3 Vectors
    var vectorData = VectorData.builder()
            .float32(embeddings)
            .build();

    // Build the input vector (metadata is optional)
    var inputVector = PutInputVector.builder()
            .key(key)
            // .metadata(document)   // uncomment if you have filterable metadata
            .data(vectorData)
            .build();

    // Build the request that targets the bucket + index created earlier
    var putRequest = PutVectorsRequest.builder()
            .vectorBucketName(VECTOR_BUCKET)
            .indexName(INDEX_NAME)
            .vectors(inputVector)          // you can also pass a collection for bulk writes
            .build();

    S3_VECTORS_CLIENT.putVectors(putRequest);
}

Performance tip: If you have many embeddings, batch them into a single PutVectorsRequest (by supplying a collection of PutInputVectors). This reduces round‑trips and improves throughput.

Next steps

  • Implement the analogous image‑embedding flow (the same pattern, just a different payload).
  • Explore filterable metadata to enable richer queries.
  • Experiment with different distance metrics and embedding dimensions to find the best trade‑off for your use case.

Happy embedding! 🚀

Creating and Storing Text Embeddings

T.putVectors(pvRequest);

To test creating and storing the text embeddings, uncomment the invocations in the main method.
The second parameter represents the key used in the PutInputVector object.

public static void main(String[] args) throws Exception {
    createAndStoreTextEmbeddings(AWS_LAMBDA_EMBEDDINGS, "AWS Lambda Definition");
    createAndStoreTextEmbeddings(AZURE_FUNCTIONS__EMBEDDINGS, "Azure Functions Definition");
}

We’ll reuse many parts from the process described above.
The relevant business logic of our sample application can still be found in AmazonNovaMultimodalEmbeddings.
The method of interest is createAndStoreImageEmbeddings.

Differences Between Text and Image Embeddings

  • Text embeddings – the JSON request contains a text element.
  • Image embeddings – the JSON request contains an image element, where we specify:
    • format as jpeg
    • sources3Locationuri pointing to the image in S3

Both test images (visually describing AWS Lambda and Azure Functions) have been uploaded to an S3 bucket created for this purpose:

private static final String S3_BUCKET = "s3://vk-amazon-nova-2-mme/";   // replace with your own bucket

Image names are defined as:

private static final String[] IMAGE_NAMES = { "AWS-Lambda", "Azure-Functions" };

For each image we build an S3_IMAGE_URI using the bucket, image name, and extension, then create the JSON request, invoke the Bedrock model, and store the resulting embedding in Amazon S3 Vectors using the image name as the key (the same approach used for text embeddings).

Complete Source Code for createAndStoreImageEmbeddings

private static void createAndStoreImageEmbeddings() throws Exception {
    for (String imageName : IMAGE_NAMES) {
        String request = """
        {
            "taskType": "SINGLE_EMBEDDING",
            "segmentedEmbeddingParams": {
                "embeddingPurpose": "GENERIC_INDEX",
                "embeddingDimension": {{dimension}},
                "image": {
                    "format": "jpeg",
                    "source": {
                        "s3Location": { "uri": {{S3_IMAGE_URI}} }
                    }
                }
            }
        }
        """
        .replace("{{S3_IMAGE_URI}}",
                 "\"" + S3_BUCKET + imageName + IMAGE_EXTENSION + "\"")
        .replace("{{dimension}}", String.valueOf(EMBEDDING_DIMENSION));

        var eResponse = invokeBedrockModel(request);
        putVectors(eResponse.embeddings().getFirst().embedding(), imageName);
    }
}

Testing Image Embeddings

Uncomment the following line in main to run the image‑embedding workflow:

public static void main(String[] args) throws Exception {
    createAndStoreImageEmbeddings();
}

Recap

  • Demonstrated how to create text and image embeddings with Amazon Nova 2 Multimodal Embeddings.
  • Showed how to store the embeddings in Amazon S3 Vectors using the AWS Java SDK.

In the next part of the series we’ll explore audio and video embeddings.

Back to Blog

Related posts

Read more »

PageSpeed 70 vs 95: the true reality

Introduction Let’s be honest from the start: if you have a website for an accounting firm, a psychologist, a real estate agency, a barbershop, a clinic, an off...

What is AWS Bedrock??

Why Does Bedrock Even Exist? Let's rewind a bit. Around 2022‑2023, companies were going absolutely wild over generative AI. ChatGPT had just blown up. Every st...