{"id":2994,"date":"2024-07-25T08:51:41","date_gmt":"2024-07-25T15:51:41","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=2994"},"modified":"2024-07-26T09:04:19","modified_gmt":"2024-07-26T16:04:19","slug":"announcing-semantic-kernel-for-java-1-2-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/announcing-semantic-kernel-for-java-1-2-0\/","title":{"rendered":"Announcing Semantic Kernel for Java 1.2.0"},"content":{"rendered":"<p>Hello Java AI developers!<\/p>\n<p>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.<\/p>\n<h2>What\u2019s New in Semantic Kernel for Java v1.2.0?<\/h2>\n<h3>A new dedicated repository<\/h3>\n<p>To get greater awareness of the Java version of Semantic Kernel, we&#8217;ve created a separate Java repository for it. Several folks had difficulty finding updates to the Java project, so it&#8217;s now much easier to find at <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\">github.com\/microsoft\/semantic-kernel-java<\/a>.<\/p>\n<p>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: <a href=\"https:\/\/github.com\/orgs\/microsoft\/projects\/866\/views\/1?filterQuery=-status%3A%22No+Status%22%2CReleased%2C%22Backlog*%22%2CEpic%2C%22V1+Drafts%22+sprint%3A%40current+Language%3AJava\">Current Sprint \u00b7 Semantic Kernel for Java.<\/a><\/p>\n<h3>Fixes<\/h3>\n<p>We have addressed several issues reported to use by the community. Here are some of the key fixes included in this release:<\/p>\n<ul>\n<li><strong>History Duplication on Invocation Error<\/strong>: Fixed an issue where chat history would duplicate upon invocation errors.<\/li>\n<li><strong>Type Conversion Robustness<\/strong>: Enhanced type conversion mechanisms to improve reliability in data processing.<\/li>\n<li><strong>LAST_MESSAGE_ONLY Fix<\/strong>: Corrected the LAST_MESSAGE_ONLY functionality to ensure it correctly handles and displays the last message only.<\/li>\n<\/ul>\n<h3>New Features<\/h3>\n<ul>\n<li><strong>Added support for Chat Content to include image_url content:<\/strong> We have improved the content accepted for an OpenAI chat completion.\n<ul>\n<li>Added ChatMessageTextContent and ChatMessageImageContent which extend the existing ChatMessageContent class.<\/li>\n<li>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.<\/li>\n<li>Constructors of ChatMessageContent were also modified to support this change.\n<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/chatcompletion\/Example_ChatWithVision.java\">See the sample code here.<\/a><\/li>\n<\/ul>\n<\/li>\n<li><strong>Added Gemini support:<\/strong> The code may be found in the <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/tree\/main\/aiservices\/google\">aiservices\/google module.\n<\/a><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/chatcompletion\/Example96_GeminiChatCompletion.java\">See the sample code here.<\/a> (<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/functions\/Example98_GeminiFunctionCalling.java\">and here as well<\/a>)<\/li>\n<li><strong>OpenTelemetry (otel) integration<\/strong>: Added telemetry on chat and text completions to help watch and analyze performance and usage.<\/li>\n<li><strong>Presidio Integration<\/strong>: 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.\n<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/tree\/main\/samples\/semantickernel-demos\/sk-presidio-sample\">See the sample code here<\/a>.<\/li>\n<li><strong>Move <\/strong><strong>XML parsing classes:<\/strong> We have moved these to the implementation package as they are not expected to be used by users.<\/li>\n<\/ul>\n<h3>Experimental Features<\/h3>\n<p>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.<\/p>\n<h4>Hugging Face<\/h4>\n<p><a href=\"https:\/\/huggingface.co\/\">Hugging Face<\/a> is a machine learning platform with models for text and natural language processing. The source for the Hugging Face implementation is in the <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/tree\/main\/aiservices\/huggingface\">aiservices\/huggingface<\/a> module.\n<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/Example20_HuggingFace.java\">See the sample code here.<\/a><\/p>\n<h4>Vector store databases:<\/h4>\n<p>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\u2019s needs. This semantic memory can be used to generate content based on the stored information.<\/p>\n<p>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 <a href=\"https:\/\/azure.microsoft.com\/en-us\/products\/ai-services\/ai-search\/\">Azure AI Search<\/a> and another for <a href=\"https:\/\/redis.io\/docs\/latest\/develop\/interact\/search-and-query\/query\/vector-search\/\">Redis Vector Search<\/a>. The code can be found in the <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/tree\/main\/semantickernel-experimental\">semantickernel-experimental<\/a> module. <em>Note that this feature is still incomplete, we have plans to also include a JDBC implementation module.<\/em><\/p>\n<h2>Using Semantic Kernel Memory (Experimental)<\/h2>\n<h3>Azure AI Search (experimental)<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/search\/search-what-is-azure-search\">Azure AI Search<\/a> 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.<\/p>\n<p>To manage information using Azure AI Search, start by creating a model to <a id=\"post-2994-_Int_lFWlVXES\"><\/a>represent the records stored in the vector database. This model should include a key field to uniquely <a id=\"post-2994-_Int_hTX3wsCU\"><\/a>identify each record, data fields for the information you want to store, and vector fields for any associated vector embeddings. For example:<\/p>\n<pre class=\"prettyprint language-java\"><code class=\"language-java\">class GitHubFile {\r\n    @VectorStoreRecordKeyAttribute()\r\n    private final String id;\r\n    @VectorStoreRecordDataAttribute(hasEmbedding = true, embeddingFieldName = \"embedding\")\r\n    private final String description;\r\n    @VectorStoreRecordDataAttribute\r\n    private final String link;\r\n    @VectorStoreRecordVectorAttribute(dimensions = 1536)\r\n    private final List&lt;Float&gt; embedding;\r\n}<\/code><\/pre>\n<p>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 <a id=\"post-2994-_Int_CmOJ1MCI\"><\/a>delete records individually or in batches.<\/p>\n<pre class=\"prettyprint language-java\"><code class=\"language-java\">\/\/ Initialize the Azure AI Search client\r\nvar searchClient = new SearchIndexClientBuilder()\r\n    .endpoint(AZURE_AI_SEARCH_ENDPOINT)\r\n    .credential(new AzureKeyCredential(AZURE_AISEARCH_KEY))\r\n    .buildAsyncClient();\r\n\r\n\/\/ Create a new Azure AI Search vector store\r\nvar vectorStore = AzureAISearchVectorStore.builder()\r\n    .withClient(searchClient)\r\n    .withOptions(new AzureAISearchVectorStoreOptions())\r\n    .build();\r\n\r\nString collectionName = \"skgithubfiles\";\r\nvar collection = vectorStore.getCollection(collectionName, GitHubFile.class, null);\r\n\r\n\/\/ Generate embeddings for the description and store data\r\nvar description = \"README: Installation, getting started with Semantic Kernel, and how to contribute\";\r\nvar descriptionEmbedding = embeddingGeneration.generateEmbeddingsAsync(Collections.singletonList(description)).block().get(0);\r\ncollection.upsertAsync(new GitHubFile(\r\n    \"readme\",\r\n    description,\r\n    \"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/README.md\",\r\n    descriptionEmbedding.getVector()), null).block();\r\n\r\n\/\/ Retrieve records from the collection\r\nvar readme = collection.getAsync(\"readme\", null).block();\r\n\r\n\/\/ Query the Azure AI Search client for semantic results\r\nvar result = searchClient.getSearchAsyncClient(collectionName)\r\n    .search(\"How to get started with the Semantic Kernel?\")\r\n    .blockFirst();\r\n<\/code><\/pre>\n<p>Find a more complete example <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/memory\/AzureAISearch_DataStorage.java\">here<\/a>. Let us know your experience with the new feature in our #java <a href=\"https:\/\/aka.ms\/java-sk-discord\">Discord channel<\/a>.<\/p>\n<h3>Redis Vector Store (experimental)<\/h3>\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-cache-for-redis\/cache-overview\">Redis<\/a> 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.<\/p>\n<p>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.<\/p>\n<p>Find the example <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel-java\/blob\/main\/samples\/semantickernel-concepts\/semantickernel-syntax-examples\/src\/main\/java\/com\/microsoft\/semantickernel\/samples\/syntaxexamples\/memory\/Redis_DataStorage.java\">here<\/a>.<\/p>\n<h2>Join the Community<\/h2>\n<p>Join our Discord channel at <a href=\"https:\/\/aka.ms\/java-sk-discord\">aka.ms\/java-sk-discord<\/a> 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\u2019s roadmap and upcoming features.<\/p>\n<p>We encourage you to try out the library, provide feedback, and report any issues you <a id=\"post-2994-_Int_homwmbwC\"><\/a>encounter. Your input is invaluable to us in refining the <a id=\"post-2994-_Int_R4YNgwUl\"><\/a>API and its features.<\/p>\n<p>Happy coding and AI experimenting!<\/p>\n<p>The Microsoft Semantic Kernel for Java Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s New in Semantic [&hellip;]<\/p>\n","protected":false},"author":9388,"featured_media":2364,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[47,17,24,1],"tags":[82,20,63,81,9],"class_list":["post-2994","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","category-announcements","category-java","category-semantic-kernel","tag-announcement","tag-java","tag-microsoft-semantic-kernel","tag-release","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>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\u2019s New in Semantic [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/9388"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=2994"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/2994\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2364"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=2994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=2994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=2994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}