53 Chat API
The chat API enables interactive querying and contextual response generation by automatically augmenting LLM prompt with the results of a vector search.
Endpoint
http request
POST /api/kb/<storeName>/chat
Sample Request Payload
json
{
"chatModel": "OpenAI/gpt-4o-2024-08-06",
"question": "How can I implement PortableType in Java?",
"maxResults": 10,
"minScore": 0.7,
"fullTextWeight": 0.5,
"scoringModel": "-/ms-marco-TinyBERT-L-2-v2"
}
The `chatModel` attribute is optional. If not specified, the default/configured chat model for the store will be used.
The `scoringModel`, `minScore`, and `fullTextWeight` attributes are also optional, and behave the same way as with the `/search` endpoint above.
Sample Response
text
To implement PortableType in Java, you need to follow several steps, including annotating your classes, configuring your build tool, and setting up the POF (Portable Object Format) context. Here's a step-by-step guide based on the information provided:
Step 1: Annotate Your Class with @PortableType:
You need to annotate your classes with `@PortableType` to indicate that they are portable types. Assign a unique `id` to each class.
@PortableType(id = 1)
public class Pet {
@Portable
protected String name;
// constructors, accessors, etc.
}
@PortableType(id = 2)
public class Dog extends Pet {
@Portable
private String breed;
// constructors, accessors, etc.
}Use `@Portable` for fields that should be serialized. There are other annotations like `@PortableDate`, `@PortableArray`, etc., for specific types.
Step 2: Instrument the Classes at Compile-time
Configure Maven or Gradle Plugin:
You need to use either the Maven or Gradle POF plugin to instrument these classes at compile time. This step is crucial because it generates the necessary serialization code.
Add the following configuration to your `pom.xml`:
<plugin>
<groupId>com.oracle.coherence.ce</groupId>
<artifactId>pof-maven-plugin</artifactId>
<version>14.1.2-0-0</version>
<executions>
<execution>
<id>instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>instrument-tests</id>
<goals>
<goal>instrument-tests</goal>
</goals>
</execution>
</executions>
</plugin>
This plugin will handle the instrumentation process during the build.
The response tokens will be _streamed_ to the client as soon as they are received from the chat model, and can be handled immediately (better for responsiveness), or processed as a whole once all the tokens are received by the client.
Chat API and AI
The chat model integrates document retrieval with conversational AI to provide context-aware responses. Unlike embedding and scoring models, the chat model only supports remote models, including OCI GenAI models, OpenAI, Cohere, Anthropic, AWS Bedrock, and other LangChain4J-supported providers. This ensures access to high-quality, state-of-the-art conversational AI capabilities.
The name of the chat model is specified using the same `<provider>/<modelName>` syntax described in the [Embedding Model](#embedding-model) section above.
In the example above we have used `OpenAI/gpt-4o-2024-08-06`. To use a different model, such as `OCI/cohere.command-r-08-2024`, for example, simply change the `chatModel` property in the request payload:
json
{
"chatModel": "OCI/cohere.command-r-08-2024",
"question": "How can I implement PortableType in Java?",
"maxResults": 10,
"minScore": 0.7,
"scoringModel": "-/ms-marco-TinyBERT-L-2-v2"
}
Search & Chat Across Document Stores
Users can query multiple document stores simultaneously, enabling cross-repository search capabilities.
To do so, simply omit the store name from the search and chat endpoints described earlier. The request payload and the response are exactly the same.
Search Endpoint
http request
POST /api/kb/search
Chat Endpoint
http request
POST /api/kb/chat