diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/pom.xml b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/pom.xml
new file mode 100644
index 00000000000..535fd9f44ed
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/pom.xml
@@ -0,0 +1,98 @@
+
+
+
+
+ 4.0.0
+
+ org.springframework.ai
+ spring-ai-parent
+ 1.1.0-SNAPSHOT
+ ../../../../../../pom.xml
+
+
+ spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db
+ Spring AI Auto Configuration - Chat Memory Repository - CosmosDB
+ Spring AI Auto Configuration for CosmosDB Chat Memory Repository
+
+ https://github.com/spring-projects/spring-ai
+
+
+ https://github.com/spring-projects/spring-ai
+ git://github.com/spring-projects/spring-ai.git
+ git@github.com:spring-projects/spring-ai.git
+
+
+
+
+ org.springframework.ai
+ spring-ai-model-chat-memory-repository-cosmos-db
+ ${project.version}
+
+
+
+ org.springframework.ai
+ spring-ai-autoconfigure-model-chat-memory
+ ${project.parent.version}
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure-processor
+ true
+
+
+
+ com.azure
+ azure-spring-data-cosmos
+ ${azure-cosmos.version}
+ true
+
+
+
+ com.azure
+ azure-identity
+ ${azure-identity.version}
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.springframework.ai
+ spring-ai-test
+ ${project.version}
+ test
+
+
+
diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfiguration.java b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfiguration.java
new file mode 100644
index 00000000000..1a3ca9e9711
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfiguration.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.model.chat.memory.repository.cosmosdb.autoconfigure;
+
+import com.azure.cosmos.CosmosAsyncClient;
+import com.azure.cosmos.CosmosClientBuilder;
+import com.azure.identity.DefaultAzureCredentialBuilder;
+
+import org.springframework.ai.chat.memory.repository.cosmosdb.CosmosDBChatMemoryRepository;
+import org.springframework.ai.chat.memory.repository.cosmosdb.CosmosDBChatMemoryRepositoryConfig;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+
+/**
+ * {@link AutoConfiguration Auto-configuration} for {@link CosmosDBChatMemoryRepository}.
+ *
+ * @author Theo van Kraay
+ * @since 1.0.0
+ */
+@AutoConfiguration
+@ConditionalOnClass({ CosmosDBChatMemoryRepository.class, CosmosAsyncClient.class })
+@EnableConfigurationProperties(CosmosDBChatMemoryRepositoryProperties.class)
+public class CosmosDBChatMemoryRepositoryAutoConfiguration {
+
+ private final String agentSuffix = "SpringAI-CDBNoSQL-ChatMemoryRepository";
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnProperty(prefix = "spring.ai.chat.memory.repository.cosmosdb", name = "endpoint")
+ public CosmosAsyncClient cosmosClient(CosmosDBChatMemoryRepositoryProperties properties) {
+ if (properties.getEndpoint() == null || properties.getEndpoint().isEmpty()) {
+ throw new IllegalArgumentException(
+ "Cosmos DB endpoint must be provided via spring.ai.chat.memory.repository.cosmosdb.endpoint property");
+ }
+
+ String mode = properties.getConnectionMode();
+ if (mode == null) {
+ properties.setConnectionMode("gateway");
+ }
+ else if (!mode.equals("direct") && !mode.equals("gateway")) {
+ throw new IllegalArgumentException("Connection mode must be either 'direct' or 'gateway'");
+ }
+
+ CosmosClientBuilder builder = new CosmosClientBuilder().endpoint(properties.getEndpoint())
+ .userAgentSuffix(this.agentSuffix);
+
+ if (properties.getKey() == null || properties.getKey().isEmpty()) {
+ builder.credential(new DefaultAzureCredentialBuilder().build());
+ }
+ else {
+ builder.key(properties.getKey());
+ }
+
+ return ("direct".equals(properties.getConnectionMode()) ? builder.directMode() : builder.gatewayMode())
+ .buildAsyncClient();
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public CosmosDBChatMemoryRepositoryConfig cosmosDBChatMemoryRepositoryConfig(
+ CosmosDBChatMemoryRepositoryProperties properties, CosmosAsyncClient cosmosAsyncClient) {
+
+ return CosmosDBChatMemoryRepositoryConfig.builder()
+ .withCosmosClient(cosmosAsyncClient)
+ .withDatabaseName(properties.getDatabaseName())
+ .withContainerName(properties.getContainerName())
+ .withPartitionKeyPath(properties.getPartitionKeyPath())
+ .build();
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ public CosmosDBChatMemoryRepository cosmosDBChatMemoryRepository(CosmosDBChatMemoryRepositoryConfig config) {
+ return CosmosDBChatMemoryRepository.create(config);
+ }
+
+}
diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryProperties.java b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryProperties.java
new file mode 100644
index 00000000000..56e813d263b
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryProperties.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.model.chat.memory.repository.cosmosdb.autoconfigure;
+
+import org.springframework.ai.chat.memory.repository.cosmosdb.CosmosDBChatMemoryRepositoryConfig;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Configuration properties for CosmosDB chat memory.
+ *
+ * @author Theo van Kraay
+ * @since 1.0.0
+ */
+@ConfigurationProperties(CosmosDBChatMemoryRepositoryProperties.CONFIG_PREFIX)
+public class CosmosDBChatMemoryRepositoryProperties {
+
+ public static final String CONFIG_PREFIX = "spring.ai.chat.memory.repository.cosmosdb";
+
+ private String endpoint;
+
+ private String key;
+
+ private String connectionMode = "gateway";
+
+ private String databaseName = CosmosDBChatMemoryRepositoryConfig.DEFAULT_DATABASE_NAME;
+
+ private String containerName = CosmosDBChatMemoryRepositoryConfig.DEFAULT_CONTAINER_NAME;
+
+ private String partitionKeyPath = CosmosDBChatMemoryRepositoryConfig.DEFAULT_PARTITION_KEY_PATH;
+
+ public String getEndpoint() {
+ return this.endpoint;
+ }
+
+ public void setEndpoint(String endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public String getKey() {
+ return this.key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getConnectionMode() {
+ return this.connectionMode;
+ }
+
+ public void setConnectionMode(String connectionMode) {
+ this.connectionMode = connectionMode;
+ }
+
+ public String getDatabaseName() {
+ return this.databaseName;
+ }
+
+ public void setDatabaseName(String databaseName) {
+ this.databaseName = databaseName;
+ }
+
+ public String getContainerName() {
+ return this.containerName;
+ }
+
+ public void setContainerName(String containerName) {
+ this.containerName = containerName;
+ }
+
+ public String getPartitionKeyPath() {
+ return this.partitionKeyPath;
+ }
+
+ public void setPartitionKeyPath(String partitionKeyPath) {
+ this.partitionKeyPath = partitionKeyPath;
+ }
+
+}
diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 00000000000..411c013dcb8
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+org.springframework.ai.model.chat.memory.repository.cosmosdb.autoconfigure.CosmosDBChatMemoryRepositoryAutoConfiguration
diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfigurationIT.java b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfigurationIT.java
new file mode 100644
index 00000000000..5b3d6f1d9da
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryAutoConfigurationIT.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.model.chat.memory.repository.cosmosdb.autoconfigure;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import org.springframework.ai.chat.memory.repository.cosmosdb.CosmosDBChatMemoryRepository;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.MessageType;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for {@link CosmosDBChatMemoryRepositoryAutoConfiguration}.
+ *
+ * @author Theo van Kraay
+ * @since 1.0.0
+ */
+@EnabledIfEnvironmentVariable(named = "AZURE_COSMOSDB_ENDPOINT", matches = ".+")
+class CosmosDBChatMemoryRepositoryAutoConfigurationIT {
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(CosmosDBChatMemoryRepositoryAutoConfiguration.class))
+ .withPropertyValues(
+ "spring.ai.chat.memory.repository.cosmosdb.endpoint=" + System.getenv("AZURE_COSMOSDB_ENDPOINT"))
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.database-name=test-database")
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.container-name=autoconfig-test-container");
+
+ @Test
+ void addAndGet() {
+ this.contextRunner.run(context -> {
+ CosmosDBChatMemoryRepository memory = context.getBean(CosmosDBChatMemoryRepository.class);
+
+ String conversationId = UUID.randomUUID().toString();
+ assertThat(memory.findByConversationId(conversationId)).isEmpty();
+
+ memory.saveAll(conversationId, List.of(new UserMessage("test question")));
+
+ assertThat(memory.findByConversationId(conversationId)).hasSize(1);
+ assertThat(memory.findByConversationId(conversationId).get(0).getMessageType()).isEqualTo(MessageType.USER);
+ assertThat(memory.findByConversationId(conversationId).get(0).getText()).isEqualTo("test question");
+
+ memory.deleteByConversationId(conversationId);
+ assertThat(memory.findByConversationId(conversationId)).isEmpty();
+
+ memory.saveAll(conversationId,
+ List.of(new UserMessage("test question"), new AssistantMessage("test answer")));
+
+ assertThat(memory.findByConversationId(conversationId)).hasSize(2);
+ assertThat(memory.findByConversationId(conversationId).get(0).getMessageType()).isEqualTo(MessageType.USER);
+ assertThat(memory.findByConversationId(conversationId).get(0).getText()).isEqualTo("test question");
+ assertThat(memory.findByConversationId(conversationId).get(1).getMessageType())
+ .isEqualTo(MessageType.ASSISTANT);
+ assertThat(memory.findByConversationId(conversationId).get(1).getText()).isEqualTo("test answer");
+ });
+ }
+
+ @Test
+ void propertiesConfiguration() {
+ this.contextRunner
+ .withPropertyValues(
+ "spring.ai.chat.memory.repository.cosmosdb.endpoint=" + System.getenv("AZURE_COSMOSDB_ENDPOINT"))
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.database-name=test-database")
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.container-name=custom-testcontainer")
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.partition-key-path=/customPartitionKey")
+ .run(context -> {
+ CosmosDBChatMemoryRepositoryProperties properties = context
+ .getBean(CosmosDBChatMemoryRepositoryProperties.class);
+ assertThat(properties.getEndpoint()).isEqualTo(System.getenv("AZURE_COSMOSDB_ENDPOINT"));
+ assertThat(properties.getDatabaseName()).isEqualTo("test-database");
+ assertThat(properties.getContainerName()).isEqualTo("custom-testcontainer");
+ assertThat(properties.getPartitionKeyPath()).isEqualTo("/customPartitionKey");
+ });
+ }
+
+ @Test
+ void findConversationIds() {
+ this.contextRunner.run(context -> {
+ CosmosDBChatMemoryRepository memory = context.getBean(CosmosDBChatMemoryRepository.class);
+
+ String conversationId1 = UUID.randomUUID().toString();
+ String conversationId2 = UUID.randomUUID().toString();
+
+ memory.saveAll(conversationId1, List.of(new UserMessage("test question 1")));
+ memory.saveAll(conversationId2, List.of(new UserMessage("test question 2")));
+
+ List conversationIds = memory.findConversationIds();
+ assertThat(conversationIds).contains(conversationId1, conversationId2);
+ });
+ }
+
+}
diff --git a/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryPropertiesTest.java b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryPropertiesTest.java
new file mode 100644
index 00000000000..03c972f3e3a
--- /dev/null
+++ b/auto-configurations/models/chat/memory/repository/spring-ai-autoconfigure-model-chat-memory-repository-cosmos-db/src/test/java/org/springframework/ai/model/chat/memory/repository/cosmosdb/autoconfigure/CosmosDBChatMemoryRepositoryPropertiesTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.model.chat.memory.repository.cosmosdb.autoconfigure;
+
+import org.junit.jupiter.api.Test;
+
+import org.springframework.ai.chat.memory.repository.cosmosdb.CosmosDBChatMemoryRepositoryConfig;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for {@link CosmosDBChatMemoryRepositoryProperties}.
+ *
+ * @author Theo van Kraay
+ * @since 1.0.0
+ */
+class CosmosDBChatMemoryRepositoryPropertiesTest {
+
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ .withUserConfiguration(TestConfiguration.class);
+
+ @Test
+ void defaultProperties() {
+ this.contextRunner.run(context -> {
+ CosmosDBChatMemoryRepositoryProperties properties = context
+ .getBean(CosmosDBChatMemoryRepositoryProperties.class);
+ assertThat(properties.getDatabaseName())
+ .isEqualTo(CosmosDBChatMemoryRepositoryConfig.DEFAULT_DATABASE_NAME);
+ assertThat(properties.getContainerName())
+ .isEqualTo(CosmosDBChatMemoryRepositoryConfig.DEFAULT_CONTAINER_NAME);
+ assertThat(properties.getPartitionKeyPath())
+ .isEqualTo(CosmosDBChatMemoryRepositoryConfig.DEFAULT_PARTITION_KEY_PATH);
+ });
+ }
+
+ @Test
+ void customProperties() {
+ this.contextRunner.withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.database-name=custom-db")
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.container-name=custom-container")
+ .withPropertyValues("spring.ai.chat.memory.repository.cosmosdb.partition-key-path=/custom-partition-key")
+ .run(context -> {
+ CosmosDBChatMemoryRepositoryProperties properties = context
+ .getBean(CosmosDBChatMemoryRepositoryProperties.class);
+ assertThat(properties.getDatabaseName()).isEqualTo("custom-db");
+ assertThat(properties.getContainerName()).isEqualTo("custom-container");
+ assertThat(properties.getPartitionKeyPath()).isEqualTo("/custom-partition-key");
+ });
+ }
+
+ @Configuration
+ @EnableConfigurationProperties(CosmosDBChatMemoryRepositoryProperties.class)
+ static class TestConfiguration {
+
+ }
+
+}
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/pom.xml b/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/pom.xml
new file mode 100644
index 00000000000..1872d93dc1a
--- /dev/null
+++ b/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/pom.xml
@@ -0,0 +1,76 @@
+
+
+
+
+ 4.0.0
+
+ org.springframework.ai
+ spring-ai-parent
+ 1.1.0-SNAPSHOT
+ ../../../pom.xml
+
+
+ spring-ai-model-chat-memory-repository-cosmos-db
+ Spring AI Azure Cosmos DB Chat Memory Repository
+ Spring AI Azure Cosmos DB Chat Memory Repository implementation
+
+ https://github.com/spring-projects/spring-ai
+
+
+ https://github.com/spring-projects/spring-ai
+ git://github.com/spring-projects/spring-ai.git
+ git@github.com:spring-projects/spring-ai.git
+
+
+
+
+ org.springframework.ai
+ spring-ai-model
+ ${project.version}
+
+
+
+ com.azure
+ azure-spring-data-cosmos
+ ${azure-cosmos.version}
+
+
+
+ com.azure
+ azure-identity
+ ${azure-identity.version}
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.springframework.ai
+ spring-ai-test
+ ${project.version}
+ test
+
+
+
+
+
diff --git a/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/chat/memory/repository/cosmosdb/CosmosDBChatMemoryRepository.java b/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/chat/memory/repository/cosmosdb/CosmosDBChatMemoryRepository.java
new file mode 100644
index 00000000000..a399608861b
--- /dev/null
+++ b/memory/repository/spring-ai-model-chat-memory-repository-cosmos-db/src/main/java/org/springframework/ai/chat/memory/repository/cosmosdb/CosmosDBChatMemoryRepository.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.ai.chat.memory.repository.cosmosdb;
+
+import java.time.Instant;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+import com.azure.cosmos.CosmosAsyncContainer;
+import com.azure.cosmos.models.CosmosBulkOperations;
+import com.azure.cosmos.models.CosmosItemOperation;
+import com.azure.cosmos.models.CosmosItemRequestOptions;
+import com.azure.cosmos.models.CosmosQueryRequestOptions;
+import com.azure.cosmos.models.FeedResponse;
+import com.azure.cosmos.models.PartitionKey;
+import com.azure.cosmos.models.SqlParameter;
+import com.azure.cosmos.models.SqlQuerySpec;
+import com.azure.cosmos.util.CosmosPagedFlux;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import reactor.core.publisher.Flux;
+
+import org.springframework.ai.chat.memory.ChatMemoryRepository;
+import org.springframework.ai.chat.messages.AssistantMessage;
+import org.springframework.ai.chat.messages.Message;
+import org.springframework.ai.chat.messages.MessageType;
+import org.springframework.ai.chat.messages.SystemMessage;
+import org.springframework.ai.chat.messages.ToolResponseMessage;
+import org.springframework.ai.chat.messages.UserMessage;
+import org.springframework.util.Assert;
+
+/**
+ * An implementation of {@link ChatMemoryRepository} for Azure Cosmos DB.
+ *
+ * @author Theo van Kraay
+ * @since 1.0.0
+ */
+public final class CosmosDBChatMemoryRepository implements ChatMemoryRepository {
+
+ public static final String CONVERSATION_TS = CosmosDBChatMemoryRepository.class.getSimpleName()
+ + "_message_timestamp";
+
+ private static final Logger logger = LoggerFactory.getLogger(CosmosDBChatMemoryRepository.class);
+
+ private final CosmosAsyncContainer container;
+
+ private CosmosDBChatMemoryRepository(CosmosDBChatMemoryRepositoryConfig config) {
+ Assert.notNull(config, "config cannot be null");
+ this.container = config.getContainer();
+ }
+
+ public static CosmosDBChatMemoryRepository create(CosmosDBChatMemoryRepositoryConfig config) {
+ return new CosmosDBChatMemoryRepository(config);
+ }
+
+ @Override
+ public List findConversationIds() {
+ logger.info("Finding all conversation IDs from Cosmos DB");
+
+ String query = "SELECT DISTINCT c.conversationId FROM c";
+ SqlQuerySpec querySpec = new SqlQuerySpec(query);
+
+ CosmosPagedFlux