[Developer] #570 show vector VPD effective SQL trace
This commit is contained in:
@@ -142,7 +142,9 @@ public class OrdsProbeService {
|
||||
prettyHeaders(response.getHeaders()),
|
||||
prettyJson(response.getBody())
|
||||
);
|
||||
if (!result.hasSqlTrace() && !isVectorSearchObject(object)) {
|
||||
if (isVectorSearchObject(object)) {
|
||||
result = addVectorSqlTrace(result, command.bearerToken(), object);
|
||||
} else if (!result.hasSqlTrace()) {
|
||||
result = addLocalSqlTrace(result, command.bearerToken(), object);
|
||||
}
|
||||
return auditAndReturn(command, result);
|
||||
@@ -257,6 +259,24 @@ public class OrdsProbeService {
|
||||
return result.withSqlTrace(predicate, effectiveSql);
|
||||
}
|
||||
|
||||
private ProbeResult addVectorSqlTrace(ProbeResult result, String bearerToken, ProtectedObject object) {
|
||||
String predicate = findVpdPredicate(bearerToken, object);
|
||||
if (predicate == null || predicate.isBlank()) {
|
||||
return result;
|
||||
}
|
||||
return result.withSqlTrace(predicate, vectorEffectiveSql(object, predicate));
|
||||
}
|
||||
|
||||
static String vectorEffectiveSql(ProtectedObject object, String predicate) {
|
||||
return "SELECT chunk_id, document_id, chunk_no, title, chunk_text, source_uri, tech_tag, score"
|
||||
+ " FROM (SELECT d.chunk_id, d.document_id, d.chunk_no, d.title, d.chunk_text,"
|
||||
+ " d.source_uri, d.tech_tag, VECTOR_DISTANCE(d.embedding, TO_VECTOR(:embedding), COSINE) AS score"
|
||||
+ " FROM " + object.owner() + "." + object.objectName() + " d"
|
||||
+ " WHERE d.embedding IS NOT NULL AND (" + predicate + ")"
|
||||
+ " ORDER BY score) ranked_chunks"
|
||||
+ " WHERE ROWNUM <= LEAST(GREATEST(NVL(:row_limit, 10), 1), 100)";
|
||||
}
|
||||
|
||||
private String findVpdPredicate(String bearerToken, ProtectedObject object) {
|
||||
try {
|
||||
return jdbcTemplate.execute((ConnectionCallback<String>) connection -> {
|
||||
|
||||
Reference in New Issue
Block a user