Skip to content

Commit c5508a8

Browse files
committed
COH-32687: Configuration: Models
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 118717]
1 parent 37933e0 commit c5508a8

File tree

41 files changed

+2322
-2192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2322
-2192
lines changed

prj/coherence-rag-parent/coherence-rag/README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This module contains the main RAG framework implementation including:
2828
- Configuration management endpoints
2929
- Real-time streaming responses
3030
- CORS support for web applications
31+
- Model configuration management
3132

3233
### 📄 **Document Processing**
3334
- Automatic document chunking with configurable parameters
@@ -128,12 +129,14 @@ public interface ModelProvider {
128129

129130
| Endpoint | Method | Description |
130131
|----------|--------|-------------|
131-
| `/api/store/{storeName}/documents` | POST | Upload and process documents |
132-
| `/api/store/{storeName}/search` | POST | Search for similar documents |
133-
| `/api/store/{storeName}/config` | GET/PUT | Store configuration management |
134-
| `/api/db/stores` | GET | List all document stores |
132+
| `/api/kb/{storeName}/docs` | POST | Upload and process documents |
133+
| `/api/kb/{storeName}/search` | POST | Search for similar documents |
134+
| `/api/kb/{storeName}/config` | GET/PUT | Store configuration management |
135+
| `/api/kb/stores` | GET | List all document stores |
135136
| `/api/config` | GET | Global configuration |
136137
| `/api/scoring/rerank` | POST | Re-rank search results |
138+
| `/api/models` | GET | List model configuration entries |
139+
| `/api/models/{type}/{provider}/{model}` | GET/PUT/DELETE | Manage model configuration (optional `?store=...`) |
137140

138141
### Configuration
139142

@@ -148,19 +151,29 @@ StoreConfig config = StoreConfig.builder()
148151
```
149152

150153
#### Model Configuration
151-
```java
152-
// Local ONNX embedding model
153-
EmbeddingModel embeddingModel = LocalOnnxEmbeddingModel.builder()
154-
.modelPath("models/all-MiniLM-L6-v2.onnx")
155-
.vocabularyPath("models/vocab.txt")
156-
.poolingMode(PoolingMode.MEAN)
157-
.build();
154+
You can manage provider-specific model configuration as JSON via the REST API. Configuration is stored under logical keys of the form `{type}:{provider}/{model}` with an optional `store` scope.
158155

159-
// Local ONNX scoring model
160-
ScoringModel scoringModel = LocalOnnxScoringModel.builder()
161-
.modelPath("models/ms-marco-MiniLM-L-12-v2.onnx")
162-
.vocabularyPath("models/vocab.txt")
163-
.build();
156+
Examples (OpenAI):
157+
158+
```bash
159+
# Upsert global chat model config (applies to all stores)
160+
curl -X PUT "http://localhost:8080/api/models/chat/OpenAI/gpt-4o-mini" \
161+
-H "Content-Type: application/json" \
162+
-d '{"temperature":0.6, "maxTokens":1024}'
163+
164+
# Get global chat model config
165+
curl -s "http://localhost:8080/api/models/chat/OpenAI/gpt-4o-mini"
166+
167+
# Upsert store-specific config (store=kb)
168+
curl -X PUT "http://localhost:8080/api/models/chat/OpenAI/gpt-4o-mini?store=kb" \
169+
-H "Content-Type: application/json" \
170+
-d '{"temperature":0.3}'
171+
172+
# Delete a config
173+
curl -X DELETE "http://localhost:8080/api/models/chat/OpenAI/gpt-4o-mini"
174+
175+
# List all configuration entries
176+
curl -s "http://localhost:8080/api/models"
164177
```
165178

166179
## Local ONNX Models

prj/coherence-rag-parent/coherence-rag/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,30 @@
2727
<dependency>
2828
<groupId>${coherence.group.id}</groupId>
2929
<artifactId>coherence</artifactId>
30-
<version>${project.version}</version>
3130
</dependency>
3231
<dependency>
3332
<groupId>${coherence.group.id}</groupId>
3433
<artifactId>coherence-hnsw</artifactId>
35-
<version>${project.version}</version>
3634
</dependency>
3735
<dependency>
3836
<groupId>${coherence.group.id}</groupId>
3937
<artifactId>coherence-lucene</artifactId>
40-
<version>${project.version}</version>
4138
</dependency>
4239
<dependency>
4340
<groupId>${coherence.group.id}</groupId>
4441
<artifactId>coherence-concurrent</artifactId>
45-
<version>${project.version}</version>
4642
</dependency>
4743
<dependency>
4844
<groupId>${coherence.group.id}</groupId>
4945
<artifactId>coherence-cdi-server</artifactId>
50-
<version>${project.version}</version>
5146
</dependency>
5247
<dependency>
5348
<groupId>${coherence.group.id}</groupId>
5449
<artifactId>coherence-mp-config</artifactId>
55-
<version>${project.version}</version>
5650
</dependency>
5751
<dependency>
5852
<groupId>${coherence.group.id}</groupId>
5953
<artifactId>coherence-json</artifactId>
60-
<version>${project.version}</version>
6154
</dependency>
6255

6356
<dependency>

prj/coherence-rag-parent/coherence-rag/src/main/java/com/oracle/coherence/rag/VectorStore.java

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
package com.oracle.coherence.rag.api;
8+
9+
import com.oracle.coherence.rag.config.ConfigKey;
10+
import com.oracle.coherence.rag.config.ConfigRepository;
11+
12+
import jakarta.enterprise.context.ApplicationScoped;
13+
import jakarta.inject.Inject;
14+
15+
import jakarta.ws.rs.Consumes;
16+
import jakarta.ws.rs.DELETE;
17+
import jakarta.ws.rs.GET;
18+
import jakarta.ws.rs.PUT;
19+
import jakarta.ws.rs.Path;
20+
import jakarta.ws.rs.PathParam;
21+
import jakarta.ws.rs.Produces;
22+
import jakarta.ws.rs.core.MediaType;
23+
import jakarta.ws.rs.core.Response;
24+
25+
import java.util.List;
26+
import java.util.Objects;
27+
28+
/**
29+
* REST API for managing model configuration documents.
30+
* <p/>
31+
* This endpoint allows CRUD operations on provider-specific model configuration
32+
* stored as raw JSON in the distributed configuration repository. Configuration
33+
* entries are addressed by a logical key composed of the model {@code type},
34+
* {@code provider}, and {@code model} name.
35+
* <p/>
36+
* Keys follow the convention: {@code "{type}:{provider}/{model}"}, for example
37+
* {@code "chat:OpenAI/gpt-4o-mini"} or {@code "embedding:OpenAI/text-embedding-3-small"}.
38+
*/
39+
@ApplicationScoped
40+
@Path("/api/models")
41+
public class Models
42+
{
43+
/**
44+
* Lists all configuration entries present in the repository.
45+
*
46+
* @return a list of configuration entries (keys)
47+
*/
48+
@GET
49+
@Produces(MediaType.APPLICATION_JSON)
50+
public Response list()
51+
{
52+
List<ConfigEntry> entries = repo.keys().stream()
53+
.map(k -> new ConfigEntry(String.valueOf(k.key())))
54+
.sorted((a, b) -> a.key.compareToIgnoreCase(b.key))
55+
.toList();
56+
57+
return Response.ok(entries).build();
58+
}
59+
60+
/**
61+
* Retrieves the JSON configuration for the specified model.
62+
*
63+
* @param type model type (e.g., {@code chat}, {@code streamingChat}, {@code embedding}, {@code scoring})
64+
* @param provider model provider (e.g., {@code OpenAI}, {@code OCI}, {@code Ollama}, {@code DeepSeek})
65+
* @param model provider-specific model name
66+
*
67+
* @return the JSON payload, or {@code 404} if not found
68+
*/
69+
@GET
70+
@Path("{type}/{provider}/{model}")
71+
@Produces(MediaType.APPLICATION_JSON)
72+
public Response get(@PathParam("type") String type,
73+
@PathParam("provider") String provider,
74+
@PathParam("model") String model)
75+
{
76+
ConfigKey key = new ConfigKey(key(type, provider, model));
77+
String json = repo.get(key);
78+
return json == null
79+
? Response.status(Response.Status.NOT_FOUND).build()
80+
: Response.ok(json).build();
81+
}
82+
83+
/**
84+
* Creates or updates the JSON configuration for the specified model.
85+
*
86+
* @param type model type
87+
* @param provider model provider
88+
* @param model provider-specific model name
89+
* @param json JSON payload to store
90+
*
91+
* @return {@code 204 No Content}
92+
*/
93+
@PUT
94+
@Path("{type}/{provider}/{model}")
95+
@Consumes(MediaType.APPLICATION_JSON)
96+
public Response put(@PathParam("type") String type,
97+
@PathParam("provider") String provider,
98+
@PathParam("model") String model,
99+
String json)
100+
{
101+
Objects.requireNonNull(json, "Configuration JSON cannot be null");
102+
ConfigKey key = new ConfigKey(key(type, provider, model));
103+
repo.put(key, json);
104+
return Response.noContent().build();
105+
}
106+
107+
/**
108+
* Deletes the configuration for the specified model, if present.
109+
*
110+
* @param type model type
111+
* @param provider model provider
112+
* @param model provider-specific model name
113+
*
114+
* @return {@code 204 No Content}
115+
*/
116+
@DELETE
117+
@Path("{type}/{provider}/{model}")
118+
public Response delete(@PathParam("type") String type,
119+
@PathParam("provider") String provider,
120+
@PathParam("model") String model)
121+
{
122+
ConfigKey key = new ConfigKey(key(type, provider, model));
123+
repo.remove(key);
124+
return Response.noContent().build();
125+
}
126+
127+
// ---- helpers ---------------------------------------------------------
128+
129+
private static String key(String type, String provider, String model)
130+
{
131+
return type + ':' + provider + '/' + model;
132+
}
133+
134+
// ---- data members ----------------------------------------------------
135+
136+
@Inject
137+
private ConfigRepository repo;
138+
139+
/** Entry returned by the list endpoint. */
140+
public record ConfigEntry(String key) {}
141+
}
142+
143+

prj/coherence-rag-parent/coherence-rag/src/main/java/com/oracle/coherence/rag/api/Store.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ public Response getDocumentChunkStats()
865865
public Response chat(ChatRequest request)
866866
{
867867
StreamingChatModel chatModel = request.chatModel() == null
868-
? chatModelSupplier.get()
868+
? chatModelSupplier.get(config().getChatModel())
869869
: chatModelSupplier.get(new ModelName(request.chatModel()));
870870
ChatAssistant assistant = createChatAssistant(chatModel, request.maxResults(), request.minScore());
871871
TokenStream answer = assistant.answer(request.question());
@@ -1113,6 +1113,7 @@ public void run()
11131113

11141114
if (doc != null)
11151115
{
1116+
doc.metadata().put("url", docId);
11161117
docs.put(docId, doc);
11171118
Logger.fine("Loaded %s in %,d ms".formatted(docId, time));
11181119
}

prj/coherence-rag-parent/coherence-rag/src/main/java/com/oracle/coherence/rag/config/AbstractConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
*/
3434
public abstract class AbstractConfig<T>
3535
extends AbstractEvolvable
36-
implements PortableObject
3736
{
3837
@JsonbTransient
3938
public int getDataVersion()
@@ -54,7 +53,7 @@ public int getImplVersion()
5453
*
5554
* @param target the object to apply configuration values to (e.g., a POJO or Builder)
5655
*/
57-
public void apply(T target)
56+
public T apply(T target)
5857
{
5958
Map<String, Method> mapSourceProperties = findReadableProperties(this.getClass());
6059
Map<String, Method> mapTargetProperties = findWritableProperties(target.getClass());
@@ -83,6 +82,8 @@ public void apply(T target)
8382
.formatted(sName, target.getClass().getName()));
8483
}
8584
}
85+
86+
return target;
8687
}
8788

8889
/**

0 commit comments

Comments
 (0)