Hello Java AI developers!
We are announcing the release of Semantic Kernel for Java v1.2.0! Since our release of v1.0 this past May, we have been working to improve and expand the capabilities we provide. Today, we are thrilled to share the latest updates, new features, and experimental features with you.
What’s New in Semantic Kernel for Java v1.2.0?
A new dedicated repository
To get greater awareness of the Java version of Semantic Kernel, we’ve created a separate Java repository for it. Several folks had difficulty finding updates to the Java project, so it’s now much easier to find at github.com/microsoft/semantic-kernel-java.
With this new repo, our goal is to make it easier for Java developers to contribute and collaborate. We still continue to track the work for the Java library in the Semantic Kernel project to keep alignment with the other languages. See the full backlog and the planned work in this sprint here: Current Sprint · Semantic Kernel for Java.
Fixes
We have addressed several issues reported to use by the community. Here are some of the key fixes included in this release:
- History Duplication on Invocation Error: Fixed an issue where chat history would duplicate upon invocation errors.
- Type Conversion Robustness: Enhanced type conversion mechanisms to improve reliability in data processing.
- LAST_MESSAGE_ONLY Fix: Corrected the LAST_MESSAGE_ONLY functionality to ensure it correctly handles and displays the last message only.
New Features
- Added support for Chat Content to include image_url content: We have improved the content accepted for an OpenAI chat completion.
- Added ChatMessageTextContent and ChatMessageImageContent which extend the existing ChatMessageContent class.
- ChatMessageContent for now defaults to a text content type for backwards compatibility. However, users are encouraged to migrate to using the builders on ChatMessageTextContent to create text-based chat messages.
- Constructors of ChatMessageContent were also modified to support this change. See the sample code here.
- Added Gemini support: The code may be found in the aiservices/google module. See the sample code here. (and here as well)
- OpenTelemetry (otel) integration: Added telemetry on chat and text completions to help watch and analyze performance and usage.
- Presidio Integration: To ensure we hold ourselves accountable to enable our users to pursue responsible AI, we have added a code sample to show how your intelligent app can integrate with Presidio. This integration will allow you to detect and redact sensitive data from prompts to include data privacy and protection in your solutions. See the sample code here.
- Move XML parsing classes: We have moved these to the implementation package as they are not expected to be used by users.
Experimental Features
These features are currently in beta. We encourage the community to try these features and to help us improve them through feedback or pull requests.
Hugging Face
Hugging Face is a machine learning platform with models for text and natural language processing. The source for the Hugging Face implementation is in the aiservices/huggingface module. See the sample code here.
Vector store databases:
Vector store databases allow you to store business data in vector embeddings that are used as long-term, semantic memory for AI applications. Essentially, now you can now store and retrieve data based on similarity specific to your application’s needs. This semantic memory can be used to generate content based on the stored information.
The Semantic Kernel for Java presents an abstract framework that allows any vector store database to be used within your application. In this release, we have two experimental implementations, one for Azure AI Search and another for Redis Vector Search. The code can be found in the semantickernel-experimental module. Note that this feature is still incomplete, we have plans to also include a JDBC implementation module.
Using Semantic Kernel Memory (Experimental)
Azure AI Search (experimental)
Azure AI Search is a text and vector search engine that provides secure information retrieval at scale over user-owned content in traditional and generative AI search applications.
To manage information using Azure AI Search, start by creating a model to represent the records stored in the vector database. This model should include a key field to uniquely identify each record, data fields for the information you want to store, and vector fields for any associated vector embeddings. For example:
class GitHubFile {
@VectorStoreRecordKeyAttribute()
private final String id;
@VectorStoreRecordDataAttribute(hasEmbedding = true, embeddingFieldName = "embedding")
private final String description;
@VectorStoreRecordDataAttribute
private final String link;
@VectorStoreRecordVectorAttribute(dimensions = 1536)
private final List<Float> embedding;
}
Next, create an AzureAISearchVectorStore to manage the collections (which correspond to indexes in Azure AI Search) in your database. With each collection, you can upsert, retrieve, and delete records individually or in batches.
// Initialize the Azure AI Search client
var searchClient = new SearchIndexClientBuilder()
.endpoint(AZURE_AI_SEARCH_ENDPOINT)
.credential(new AzureKeyCredential(AZURE_AISEARCH_KEY))
.buildAsyncClient();
// Create a new Azure AI Search vector store
var vectorStore = AzureAISearchVectorStore.builder()
.withClient(searchClient)
.withOptions(new AzureAISearchVectorStoreOptions())
.build();
String collectionName = "skgithubfiles";
var collection = vectorStore.getCollection(collectionName, GitHubFile.class, null);
// Generate embeddings for the description and store data
var description = "README: Installation, getting started with Semantic Kernel, and how to contribute";
var descriptionEmbedding = embeddingGeneration.generateEmbeddingsAsync(Collections.singletonList(description)).block().get(0);
collection.upsertAsync(new GitHubFile(
"readme",
description,
"https://github.com/microsoft/semantic-kernel-java/blob/main/README.md",
descriptionEmbedding.getVector()), null).block();
// Retrieve records from the collection
var readme = collection.getAsync("readme", null).block();
// Query the Azure AI Search client for semantic results
var result = searchClient.getSearchAsyncClient(collectionName)
.search("How to get started with the Semantic Kernel?")
.blockFirst();
Find a more complete example here. Let us know your experience with the new feature in our #java Discord channel.
Redis Vector Store (experimental)
Redis is an in-memory data structure store that functions as a versatile key-value, vector, and document database. It provides fast, secure, and scalable data retrieval, making it ideal for various applications, including real-time analytics, AI-driven search, and managing vector embeddings and documents.
Similarly, for Redis, you need to define your record model. Once defined, you can use Redis to upsert, get, and delete records, managing data efficiently, including vector embeddings, in a manner similar to Azure AI Search.
Find the example here.
Join the Community
Join our Discord channel at aka.ms/java-sk-discord to interact with other developers, ask questions, share insights, and be a part of this growing community. You can also get more information about the project’s roadmap and upcoming features.
We encourage you to try out the library, provide feedback, and report any issues you encounter. Your input is invaluable to us in refining the API and its features.
Happy coding and AI experimenting!
The Microsoft Semantic Kernel for Java Team
0 comments