Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.9.0 #136

Merged
merged 200 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
200 commits
Select commit Hold shift + click to select a range
454c365
Add support for CAII Deepseek (#121)
ewilliams-cloudera Feb 3, 2025
319621e
"wip on adding query config to sessions"
jkwatson Feb 3, 2025
3d38736
"implementing new queryConfig in java"
ewilliams-cloudera Feb 3, 2025
a28661d
"test null session query configuration"
mliu-cloudera Feb 3, 2025
8c6d406
"handle null database values"
jkwatson Feb 3, 2025
e6e6c60
"wip on fe"
ewilliams-cloudera Feb 3, 2025
776192d
"Add enableHyde to mutate"
mliu-cloudera Feb 3, 2025
9c9aa90
"fix nested form value"
ewilliams-cloudera Feb 3, 2025
d6ad942
Remove console.log()
mliu-cloudera Feb 3, 2025
6785c25
Remove use_hyde from querytime config
mliu-cloudera Feb 3, 2025
034498a
update python deps
ewilliams-cloudera Feb 3, 2025
2eeb5f2
update be for summary filter
ewilliams-cloudera Feb 3, 2025
9ac801b
"wip on moving to advanced options for sessions"
jkwatson Feb 3, 2025
982687d
"I'm not sure how to describe what I've done"
mliu-cloudera Feb 3, 2025
36f57f4
"fix nested form value"
ewilliams-cloudera Feb 4, 2025
0960558
"enable summary filtering in theUI"
jkwatson Feb 4, 2025
d7a0e78
fix issues from llama-index upgrade
jkwatson Feb 4, 2025
ad82f9b
round score to hundredth
ewilliams-cloudera Feb 4, 2025
49e817a
reorder markdown to break by section first
ewilliams-cloudera Feb 4, 2025
c0677dd
"fix markdown node metadata"
jkwatson Feb 4, 2025
b129ce1
"wip on showing path"
ewilliams-cloudera Feb 4, 2025
e22b00c
"metadata doc location layout "
jkwatson Feb 4, 2025
2f44e7c
fix mypy warning on node type
ewilliams-cloudera Feb 4, 2025
f84f826
Merge pull request #122 from cloudera/mob/main
ewilliams-cloudera Feb 4, 2025
be9fd47
Bump vitest in /ui in the npm_and_yarn group across 1 directory
dependabot[bot] Feb 4, 2025
2581e8e
Update release version to 1.9.0-alpha
actions-user Feb 4, 2025
7fb57ba
Merge pull request #123 from cloudera/dependabot/npm_and_yarn/ui/npm_…
ewilliams-cloudera Feb 4, 2025
28ee498
get mlflow running locally
ewilliams-cloudera Feb 4, 2025
88072bc
some progress on mlflow logs
ewilliams-cloudera Feb 4, 2025
d47a61a
remove run search since it was failing on cml
ewilliams-cloudera Feb 5, 2025
0767241
refactoring, plus group all the mlflow spans under a single request span
jkwatson Feb 5, 2025
e38c287
refactoring/cleanup
jkwatson Feb 5, 2025
9d9d84e
add params to data sources
ewilliams-cloudera Feb 5, 2025
f432474
"python endpoint for rating a response"
jkwatson Feb 5, 2025
770f4af
wip on ui for thumbs
ewilliams-cloudera Feb 5, 2025
3f077e0
"wip on eval mutation"
jkwatson Feb 5, 2025
df3fefe
"Add no-op onClick handler for feedback"
mliu-cloudera Feb 5, 2025
45cd687
"fill icon when clicked"
ewilliams-cloudera Feb 5, 2025
6e6e910
Add onError handler for chat feedback
mliu-cloudera Feb 5, 2025
6467369
switch to rendering markdown for responses
ewilliams-cloudera Feb 5, 2025
5e2c6c2
fix broken tests and linting
ewilliams-cloudera Feb 5, 2025
8a18988
switch naming to use feedback
ewilliams-cloudera Feb 5, 2025
49c149d
fix test
ewilliams-cloudera Feb 5, 2025
82fa9c2
Merge pull request #124 from cloudera/mob/main
ewilliams-cloudera Feb 5, 2025
a171388
add tags to experiment
ewilliams-cloudera Feb 5, 2025
3688475
add types for mypy
jkwatson Feb 6, 2025
8c5db03
remove tags from experiment
ewilliams-cloudera Feb 6, 2025
762dadd
switch checkboxes to switches
ewilliams-cloudera Feb 6, 2025
010070e
wip on adding custom feedback inputs
ewilliams-cloudera Feb 6, 2025
6732a99
"Log feedback separate from rating"
mliu-cloudera Feb 6, 2025
41cac80
"hook up feedback/ratings"
jkwatson Feb 6, 2025
6b3d37e
"finish hooking up ui"
ewilliams-cloudera Feb 6, 2025
5387621
"Start factoring out feedback"
mliu-cloudera Feb 6, 2025
0ba562a
"make things work"
jkwatson Feb 6, 2025
dd67c48
Update release version to dev-testing
actions-user Feb 6, 2025
e8cae60
finish refactoring ui
ewilliams-cloudera Feb 6, 2025
3e654e6
set default background color and height
ewilliams-cloudera Feb 6, 2025
5f1179a
bug fixes, log less data in the table, and a nascent metrics endpoint
jkwatson Feb 7, 2025
4a8b6c0
fix mypy
jkwatson Feb 7, 2025
06fe37a
get all the scores for a datasource
jkwatson Feb 7, 2025
8aa4256
dataframe it is
jkwatson Feb 7, 2025
a79dab9
add experiment tag for session_id for testing on dev
ewilliams-cloudera Feb 7, 2025
0822dff
wip on adding metrics
ewilliams-cloudera Feb 7, 2025
251f010
user tracking plus many metric things
jkwatson Feb 7, 2025
a2f0d1a
mypy cleanup
jkwatson Feb 7, 2025
11cd6ab
remove experiment tagging
jkwatson Feb 7, 2025
eb288ca
fix jwt
ewilliams-cloudera Feb 7, 2025
e2a8334
finish implementing metrics
ewilliams-cloudera Feb 7, 2025
8307522
"Call DS metrics API"
mliu-cloudera Feb 7, 2025
1d61c36
"fix bug with types"
ewilliams-cloudera Feb 7, 2025
3b0c27d
"Chartify some metrics"
mliu-cloudera Feb 7, 2025
9153d0a
wip on charts
ewilliams-cloudera Feb 8, 2025
9a7be89
upgrade packages and add rechart
ewilliams-cloudera Feb 10, 2025
7ccb2c6
work on vector graph swap to mui
ewilliams-cloudera Feb 11, 2025
7923bf4
remove recharts
ewilliams-cloudera Feb 11, 2025
6678df4
commit lock file
ewilliams-cloudera Feb 11, 2025
e8f33d3
disable the voynich manuscript
jkwatson Feb 11, 2025
2509fc9
refactor format series
ewilliams-cloudera Feb 11, 2025
ff164a2
convert the category chart to mui
jkwatson Feb 11, 2025
24e4264
wip on time chart
ewilliams-cloudera Feb 11, 2025
b67859a
cleanup
jkwatson Feb 11, 2025
b818fd0
chart formatting
ewilliams-cloudera Feb 11, 2025
40635e0
format axes more nicely
jkwatson Feb 11, 2025
2ebfc74
cleanup and remove chartjs
ewilliams-cloudera Feb 11, 2025
5586eeb
fix py
ewilliams-cloudera Feb 11, 2025
c672477
remove comments
ewilliams-cloudera Feb 11, 2025
169dd65
remove comments
ewilliams-cloudera Feb 11, 2025
abcc1bc
Merge pull request #125 from cloudera/mob/main
ewilliams-cloudera Feb 11, 2025
6c5efbf
Update release version to 1.9.0-beta
actions-user Feb 11, 2025
65d088a
move metrics generation to its own file
jkwatson Feb 11, 2025
54c3424
"Factor out filter_runs() fn"
mliu-cloudera Feb 11, 2025
5f7f79f
"wip on test for metrics"
ewilliams-cloudera Feb 11, 2025
80b9db6
"generate some random runs"
jkwatson Feb 11, 2025
5bc9577
Generate runs and their data_source_ids
mliu-cloudera Feb 11, 2025
558acc6
Unpack data_source_ids
mliu-cloudera Feb 11, 2025
8a80b19
Catch None case
mliu-cloudera Feb 11, 2025
b03d8ae
"wip on test for metrics"
ewilliams-cloudera Feb 11, 2025
7e10279
"add inference model"
jkwatson Feb 11, 2025
bd8d1b8
"wip on test for metrics"
ewilliams-cloudera Feb 11, 2025
d8bc2b1
"start adding rerank model"
jkwatson Feb 11, 2025
f413dc6
"start adding rerank model"
jkwatson Feb 11, 2025
1febebf
add reranking model and simplify all none check
ewilliams-cloudera Feb 11, 2025
d848633
implementing more filters
ewilliams-cloudera Feb 11, 2025
6bcc20b
swap out api call on fe, move to a post request
ewilliams-cloudera Feb 11, 2025
c28d12b
metric API wired up to the FE
jkwatson Feb 11, 2025
92bb824
Make 'Not helpful' even less helpful
mliu-cloudera Feb 12, 2025
4a03690
Remove old metrics endpoint
mliu-cloudera Feb 12, 2025
612b04f
Satisfy mypy
mliu-cloudera Feb 12, 2025
6a489b3
Remove unused imports
mliu-cloudera Feb 12, 2025
6f8abbb
Merge pull request #126 from cloudera/mob/main
mliu-cloudera Feb 12, 2025
833225c
change the time series to be floats for time
jkwatson Feb 12, 2025
3f7f4ab
log a few bits
jkwatson Feb 12, 2025
4e9f97f
Merge pull request #127 from cloudera/mob/main
ewilliams-cloudera Feb 12, 2025
10a4f21
print run params
jkwatson Feb 12, 2025
90998e5
log some more debug info
jkwatson Feb 12, 2025
12e9b63
get runs from experiment
jkwatson Feb 12, 2025
fca532a
pre-filter indexing experiments, based on name
jkwatson Feb 12, 2025
7ea57c5
analytics page placeholder
ewilliams-cloudera Feb 12, 2025
cfa471d
add route for highlighting analytics item
ewilliams-cloudera Feb 12, 2025
92d253e
wip on form
ewilliams-cloudera Feb 12, 2025
ba9ab5e
"watch the form, add rerank model"
jkwatson Feb 12, 2025
e4b86b4
"new option for has rerank"
ewilliams-cloudera Feb 12, 2025
152bbc1
"add filter for no/has rerank model"
jkwatson Feb 12, 2025
7935cd0
Allow no reranking model
mliu-cloudera Feb 12, 2025
34f3cc0
fix it
ewilliams-cloudera Feb 12, 2025
e663227
Factor out reused strategies
mliu-cloudera Feb 12, 2025
5dbf61e
Move mypy directive
mliu-cloudera Feb 12, 2025
0148ef7
Rename and annotate strategies
mliu-cloudera Feb 12, 2025
d335ae7
Simplify RunData creation
mliu-cloudera Feb 12, 2025
004687b
add summary filter & hyde filtering
jkwatson Feb 12, 2025
3337d69
Merge pull request #128 from cloudera/liu/metric-filter
mliu-cloudera Feb 12, 2025
08157a3
"Add exclude knowledge base, then bork the card"
mliu-cloudera Feb 12, 2025
696a225
fix form layout
ewilliams-cloudera Feb 12, 2025
a7636de
"refactor filter options into fns"
mliu-cloudera Feb 12, 2025
e295b8b
fix metrics tab & rename label on metrics page
jkwatson Feb 12, 2025
0617cac
layout tweaks, compute axis values
jkwatson Feb 12, 2025
f5ceb41
wip on adding evals
ewilliams-cloudera Feb 13, 2025
9d5f438
"fix div by 0 error"
jkwatson Feb 13, 2025
b052f78
Merge pull request #129 from cloudera/mob/main
ewilliams-cloudera Feb 13, 2025
9d90914
Simplify? metrics property-based test
mliu-cloudera Feb 13, 2025
8bdf1c3
Remove unused import
mliu-cloudera Feb 13, 2025
b91dd4c
Rename variable
mliu-cloudera Feb 13, 2025
8b41732
Handle data_source_id filter
mliu-cloudera Feb 13, 2025
74d3444
Fix check
mliu-cloudera Feb 13, 2025
4790e96
Fix data_source_id check
mliu-cloudera Feb 13, 2025
a8827b2
exclude direct llm calls from eval averages
ewilliams-cloudera Feb 13, 2025
311a131
remove unused filter
ewilliams-cloudera Feb 13, 2025
85fa3b0
format max scores to only two digits after decimal
ewilliams-cloudera Feb 13, 2025
3cff5db
start building a metrics controller
jkwatson Feb 13, 2025
299c0d1
"Lay down bricks for metricsconeteolmar test"
mliu-cloudera Feb 13, 2025
2e2032d
"wip on tests"
ewilliams-cloudera Feb 13, 2025
9ba1142
"query # of kbs"
jkwatson Feb 13, 2025
8761d84
"Finish RAG Studio metrics test"
mliu-cloudera Feb 13, 2025
7cfaa8d
basic ui for app metrics and cleanup endpoint
ewilliams-cloudera Feb 13, 2025
c6b0980
"UI for new app-level metrics"
jkwatson Feb 13, 2025
fd31724
"Hook up Java metrics endpoint to Python metrics endpoint"
mliu-cloudera Feb 13, 2025
a87e293
"fix python metadata metrics"
ewilliams-cloudera Feb 13, 2025
66693f8
"hook up metrics api, log data source params"
jkwatson Feb 13, 2025
0049915
Merge pull request #130 from cloudera/liu/simplify
mliu-cloudera Feb 13, 2025
c7c5e11
Merge pull request #131 from cloudera/mob/main
ewilliams-cloudera Feb 13, 2025
dc705a5
Define st_filter_value()
mliu-cloudera Feb 13, 2025
60444a8
Define RunDataStrategies
mliu-cloudera Feb 13, 2025
f0aeb06
Use RunDataStrategies
mliu-cloudera Feb 13, 2025
b7516b0
top_k is a param, not a metric
mliu-cloudera Feb 13, 2025
cb5dcb9
Add test case
mliu-cloudera Feb 13, 2025
b7a26b4
Set an xfail for a bug in our code
mliu-cloudera Feb 13, 2025
4571f75
Remove xfail example, for a later PR
mliu-cloudera Feb 13, 2025
c7e9f74
Rename class
mliu-cloudera Feb 14, 2025
cd07d4f
Convert lambdas to defs
mliu-cloudera Feb 14, 2025
24ab585
Remove complicated logic around data_source_ids
mliu-cloudera Feb 13, 2025
bbe84d2
Revert "Remove xfail example, for a later PR"
mliu-cloudera Feb 13, 2025
db9f489
Fix filtering
mliu-cloudera Feb 14, 2025
081031d
Check for false negatives
mliu-cloudera Feb 14, 2025
8043275
Merge pull request #132 from cloudera/liu/hypothesis
mliu-cloudera Feb 18, 2025
c6d743e
Merge pull request #133 from cloudera/liu/data-source-ids
mliu-cloudera Feb 18, 2025
5160e5b
add keys for react components
ewilliams-cloudera Feb 18, 2025
4aef508
Replace false negative check with TODO
mliu-cloudera Feb 18, 2025
171568f
Merge pull request #134 from cloudera/liu/negative-check
mliu-cloudera Feb 18, 2025
64cbc93
Update release version to 1.9.0
actions-user Feb 18, 2025
a45301a
wip on moving chat mlflow
ewilliams-cloudera Feb 19, 2025
0e92048
centralize datasources metrics to mlflow
ewilliams-cloudera Feb 19, 2025
3bf99b8
Resolve circular import
mliu-cloudera Feb 20, 2025
4dd6643
fix tests
ewilliams-cloudera Feb 20, 2025
2638691
more cleanup of mlflow
ewilliams-cloudera Feb 20, 2025
21ec428
wip on creating a reconciler
ewilliams-cloudera Feb 20, 2025
10b325a
getting close on the reconciler
ewilliams-cloudera Feb 20, 2025
0551535
small changes
ewilliams-cloudera Feb 21, 2025
41572b5
remove unnecessary check
ewilliams-cloudera Feb 21, 2025
20a7fd8
fix mypy
ewilliams-cloudera Feb 21, 2025
7ac2043
add back tracing
ewilliams-cloudera Feb 21, 2025
9a6ed39
Load JSON into MlflowRunData
mliu-cloudera Feb 21, 2025
c18ede5
Resolve circular imports
mliu-cloudera Feb 21, 2025
7abe527
Don't pass Request classes into services
mliu-cloudera Feb 21, 2025
6972ced
Create data directory before running reconciler
mliu-cloudera Feb 21, 2025
02ae01b
remove tracing and fix max score type
ewilliams-cloudera Feb 21, 2025
b3a60ba
remove unused
ewilliams-cloudera Feb 21, 2025
b420df5
fix pytests
ewilliams-cloudera Feb 21, 2025
2898dc4
remove unused
ewilliams-cloudera Feb 21, 2025
54f87a9
Create the reconciler data dir right before starting app
mliu-cloudera Feb 21, 2025
e80b155
Merge pull request #135 from cloudera/mob/mlflow-refactor
ewilliams-cloudera Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions backend/src/main/java/com/cloudera/cai/rag/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public record RagDataSource(
@Nullable Integer documentCount,
@Nullable Long totalDocSize) {}

public record QueryConfiguration(boolean enableHyde, boolean enableSummaryFilter) {}

@With
@Builder
public record Session(
Expand All @@ -116,7 +118,8 @@ public record Session(
Instant lastInteractionTime,
String inferenceModel,
String rerankModel,
Integer responseChunks) {
Integer responseChunks,
QueryConfiguration queryConfiguration) {

public static Session fromCreateRequest(CreateSession input, String username) {
return new Session(
Expand All @@ -130,14 +133,20 @@ public static Session fromCreateRequest(CreateSession input, String username) {
null,
input.inferenceModel(),
input.rerankModel(),
input.responseChunks());
input.responseChunks(),
input.queryConfiguration());
}
}

@With
public record CreateSession(
String name,
@Singular List<Long> dataSourceIds,
String inferenceModel,
String rerankModel,
Integer responseChunks) {}
Integer responseChunks,
QueryConfiguration queryConfiguration) {}

public record MetadataMetrics(
int numberOfDataSources, int numberOfSessions, int numberOfDocuments) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ public void deleteDataSource(Long id) {
handle -> handle.execute("UPDATE RAG_DATA_SOURCE SET DELETED = ? where ID = ?", true, id));
}

public int getNumberOfDataSources() {
return jdbi.withHandle(
handle -> {
try (var query = handle.createQuery("SELECT count(*) FROM RAG_DATA_SOURCE")) {
return query.mapTo(Integer.class).one();
}
});
}

// Nullables stuff below here.

public static RagDataSourceRepository createNull() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,13 @@ public RagDocument getRagDocumentById(Long id) {
}
});
}

public int getNumberOfRagDocuments() {
return jdbi.withHandle(
handle -> {
try (var query = handle.createQuery("SELECT count(*) FROM rag_data_source_document")) {
return query.mapTo(Integer.class).one();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* CLOUDERA APPLIED MACHINE LEARNING PROTOTYPE (AMP)
* (C) Cloudera, Inc. 2024
* All rights reserved.
*
* Applicable Open Source License: Apache 2.0
*
* NOTE: Cloudera open source products are modular software products
* made up of hundreds of individual components, each of which was
* individually copyrighted. Each Cloudera open source product is a
* collective work under U.S. Copyright Law. Your license to use the
* collective work is as provided in your written agreement with
* Cloudera. Used apart from the collective work, this file is
* licensed for your use pursuant to the open source license
* identified above.
*
* This code is provided to you pursuant a written agreement with
* (i) Cloudera, Inc. or (ii) a third-party authorized to distribute
* this code. If you do not have a written agreement with Cloudera nor
* with an authorized and properly licensed third party, you do not
* have any rights to access nor to use this code.
*
* Absent a written agreement with Cloudera, Inc. ("Cloudera") to the
* contrary, A) CLOUDERA PROVIDES THIS CODE TO YOU WITHOUT WARRANTIES OF ANY
* KIND; (B) CLOUDERA DISCLAIMS ANY AND ALL EXPRESS AND IMPLIED
* WARRANTIES WITH RESPECT TO THIS CODE, INCLUDING BUT NOT LIMITED TO
* IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE; (C) CLOUDERA IS NOT LIABLE TO YOU,
* AND WILL NOT DEFEND, INDEMNIFY, NOR HOLD YOU HARMLESS FOR ANY CLAIMS
* ARISING FROM OR RELATED TO THE CODE; AND (D)WITH RESPECT TO YOUR EXERCISE
* OF ANY RIGHTS GRANTED TO YOU FOR THE CODE, CLOUDERA IS NOT LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR
* CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, DAMAGES
* RELATED TO LOST REVENUE, LOST PROFITS, LOSS OF INCOME, LOSS OF
* BUSINESS ADVANTAGE OR UNAVAILABILITY, OR LOSS OR CORRUPTION OF
* DATA.
*/

package com.cloudera.cai.rag.metrics;

import com.cloudera.cai.rag.Types;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/api/v1/rag/metrics")
public class MetricsController {
private final MetricsService metricsService;

public MetricsController(MetricsService metricsService) {
this.metricsService = metricsService;
}

@GetMapping(produces = "application/json")
public Types.MetadataMetrics getMetrics() {
return metricsService.getMetrics();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* CLOUDERA APPLIED MACHINE LEARNING PROTOTYPE (AMP)
* (C) Cloudera, Inc. 2024
* All rights reserved.
*
* Applicable Open Source License: Apache 2.0
*
* NOTE: Cloudera open source products are modular software products
* made up of hundreds of individual components, each of which was
* individually copyrighted. Each Cloudera open source product is a
* collective work under U.S. Copyright Law. Your license to use the
* collective work is as provided in your written agreement with
* Cloudera. Used apart from the collective work, this file is
* licensed for your use pursuant to the open source license
* identified above.
*
* This code is provided to you pursuant a written agreement with
* (i) Cloudera, Inc. or (ii) a third-party authorized to distribute
* this code. If you do not have a written agreement with Cloudera nor
* with an authorized and properly licensed third party, you do not
* have any rights to access nor to use this code.
*
* Absent a written agreement with Cloudera, Inc. ("Cloudera") to the
* contrary, A) CLOUDERA PROVIDES THIS CODE TO YOU WITHOUT WARRANTIES OF ANY
* KIND; (B) CLOUDERA DISCLAIMS ANY AND ALL EXPRESS AND IMPLIED
* WARRANTIES WITH RESPECT TO THIS CODE, INCLUDING BUT NOT LIMITED TO
* IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE; (C) CLOUDERA IS NOT LIABLE TO YOU,
* AND WILL NOT DEFEND, INDEMNIFY, NOR HOLD YOU HARMLESS FOR ANY CLAIMS
* ARISING FROM OR RELATED TO THE CODE; AND (D)WITH RESPECT TO YOUR EXERCISE
* OF ANY RIGHTS GRANTED TO YOU FOR THE CODE, CLOUDERA IS NOT LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR
* CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, DAMAGES
* RELATED TO LOST REVENUE, LOST PROFITS, LOSS OF INCOME, LOSS OF
* BUSINESS ADVANTAGE OR UNAVAILABILITY, OR LOSS OR CORRUPTION OF
* DATA.
*/

package com.cloudera.cai.rag.metrics;

import com.cloudera.cai.rag.Types;
import com.cloudera.cai.rag.datasources.RagDataSourceRepository;
import com.cloudera.cai.rag.files.RagFileRepository;
import com.cloudera.cai.rag.sessions.SessionRepository;
import org.springframework.stereotype.Component;

@Component
public class MetricsService {
private final RagDataSourceRepository ragDataSourceRepository;
private final SessionRepository sessionRepository;
private final RagFileRepository ragFileRepository;

public MetricsService(
RagDataSourceRepository ragDataSourceRepository,
SessionRepository sessionRepository,
RagFileRepository ragFileRepository) {
this.ragDataSourceRepository = ragDataSourceRepository;
this.sessionRepository = sessionRepository;
this.ragFileRepository = ragFileRepository;
}

public Types.MetadataMetrics getMetrics() {
var numberOfDataSources = ragDataSourceRepository.getNumberOfDataSources();
var numberOfSessions = sessionRepository.getNumberOfSessions();
var numberOfDocuments = ragFileRepository.getNumberOfRagDocuments();
return new Types.MetadataMetrics(numberOfDataSources, numberOfSessions, numberOfDocuments);
}

public static MetricsService createNull() {
return new MetricsService(
RagDataSourceRepository.createNull(),
SessionRepository.createNull(),
RagFileRepository.createNull());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.cloudera.cai.rag.Types;
import com.cloudera.cai.rag.configuration.JdbiConfiguration;
import com.cloudera.cai.util.exceptions.NotFound;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Instant;
import java.util.List;
import java.util.Map;
Expand All @@ -54,7 +56,10 @@

@Component
public class SessionRepository {
public static final Types.QueryConfiguration DEFAULT_QUERY_CONFIGURATION =
new Types.QueryConfiguration(false, true);
private final Jdbi jdbi;
private final ObjectMapper objectMapper = new ObjectMapper();

public SessionRepository(Jdbi jdbi) {
this.jdbi = jdbi;
Expand All @@ -65,8 +70,8 @@ public Long create(Types.Session input) {
handle -> {
var sql =
"""
INSERT INTO CHAT_SESSION (name, created_by_id, updated_by_id, inference_model, rerank_model, response_chunks)
VALUES (:name, :createdById, :updatedById, :inferenceModel, :rerankModel, :responseChunks)
INSERT INTO CHAT_SESSION (name, created_by_id, updated_by_id, inference_model, rerank_model, response_chunks, query_configuration)
VALUES (:name, :createdById, :updatedById, :inferenceModel, :rerankModel, :responseChunks, :queryConfiguration)
""";
Long id = insertSession(input, handle, sql);
insertSessionDataSources(handle, id, input.dataSourceIds());
Expand All @@ -90,8 +95,13 @@ INSERT INTO CHAT_SESSION_DATA_SOURCE (chat_session_id, data_source_id)

private Long insertSession(Types.Session input, Handle handle, String sql) {
try (var update = handle.createUpdate(sql)) {
Types.QueryConfiguration queryConfiguration = input.queryConfiguration();
String json = objectMapper.writeValueAsString(queryConfiguration);
update.bind("queryConfiguration", json);
update.bindMethods(input);
return update.executeAndReturnGeneratedKeys("id").mapTo(Long.class).one();
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -119,26 +129,47 @@ private Stream<Types.Session.SessionBuilder> querySessions(Query query) {
Types.Session.SessionBuilder sessionBuilder =
map.computeIfAbsent(
rowView.getColumn("id", Long.class),
sessionId ->
Types.Session.builder()
sessionId -> {
try {
var queryConfiguration = extractQueryConfiguration(rowView);
return Types.Session.builder()
.id(sessionId)
.name(rowView.getColumn("name", String.class))
.inferenceModel(rowView.getColumn("inference_model", String.class))
.responseChunks(rowView.getColumn("response_chunks", Integer.class))
.rerankModel(rowView.getColumn("rerank_model", String.class))
.queryConfiguration(queryConfiguration)
.createdById(rowView.getColumn("created_by_id", String.class))
.timeCreated(rowView.getColumn("time_created", Instant.class))
.updatedById(rowView.getColumn("updated_by_id", String.class))
.timeUpdated(rowView.getColumn("time_updated", Instant.class))
.lastInteractionTime(
rowView.getColumn("last_interaction_time", Instant.class)));
rowView.getColumn("last_interaction_time", Instant.class));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});
if (rowView.getColumn("data_source_id", Long.class) != null) {
sessionBuilder.dataSourceId(rowView.getColumn("data_source_id", Long.class));
}
});
}
}

private Types.QueryConfiguration extractQueryConfiguration(RowView rowView)
throws JsonProcessingException {
String queryConfigurationJson = rowView.getColumn("query_configuration", String.class);
if (queryConfigurationJson == null) {
return DEFAULT_QUERY_CONFIGURATION;
}
Types.QueryConfiguration queryConfiguration =
objectMapper.readValue(queryConfigurationJson, Types.QueryConfiguration.class);
if (queryConfiguration == null) {
return DEFAULT_QUERY_CONFIGURATION;
}
return queryConfiguration;
}

public List<Types.Session> getSessions() {
return jdbi.withHandle(
handle -> {
Expand All @@ -155,27 +186,49 @@ public List<Types.Session> getSessions() {
});
}

public static SessionRepository createNull() {
return new SessionRepository(JdbiConfiguration.createNull());
}

public void delete(Long id) {
jdbi.useHandle(
handle -> handle.execute("UPDATE CHAT_SESSION SET DELETED = ? WHERE ID = ?", true, id));
}

public void update(Types.Session input) {
var updatedInput = input.withTimeUpdated(Instant.now());
String json = serializeQueryConfiguration(input);
jdbi.useHandle(
handle -> {
var sql =
"""
UPDATE CHAT_SESSION
SET name = :name, updated_by_id = :updatedById, inference_model = :inferenceModel,
response_chunks = :responseChunks, time_updated = :timeUpdated, rerank_model = :rerankModel
WHERE id = :id
""";
handle.createUpdate(sql).bindMethods(updatedInput).execute();
UPDATE CHAT_SESSION
SET name = :name, updated_by_id = :updatedById, inference_model = :inferenceModel, query_configuration = :queryConfiguration,
response_chunks = :responseChunks, time_updated = :timeUpdated, rerank_model = :rerankModel
WHERE id = :id
""";
handle
.createUpdate(sql)
.bind("queryConfiguration", json)
.bindMethods(updatedInput)
.execute();
});
}

private String serializeQueryConfiguration(Types.Session input) {
try {
return objectMapper.writeValueAsString(input.queryConfiguration());
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

public int getNumberOfSessions() {
return jdbi.withHandle(
handle -> {
try (var query = handle.createQuery("SELECT count(*) FROM CHAT_SESSION")) {
return query.mapTo(Integer.class).one();
}
});
}

public static SessionRepository createNull() {
return new SessionRepository(JdbiConfiguration.createNull());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* CLOUDERA APPLIED MACHINE LEARNING PROTOTYPE (AMP)
* (C) Cloudera, Inc. 2024
* All rights reserved.
Expand Down Expand Up @@ -76,5 +76,5 @@ public String extractUsername(Cookie[] cookies) {
return "unknown";
}

public record JwtCookie(String username) {}
record JwtCookie(String username) {}
}
Loading