Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ protected void doDelete(Filter.Expression filterExpression) {
try {
String nativeFilterExpression = this.filterExpressionConverter.convertExpression(filterExpression);

String sql = String.format("DELETE FROM %s WHERE %s", getFullyQualifiedTableName(), nativeFilterExpression);
String sql = "DELETE FROM ? WHERE ?";

logger.debug("Executing delete with filter: {}", sql);

this.jdbcTemplate.update(sql);
this.jdbcTemplate.update(sql, getFullyQualifiedTableName(), nativeFilterExpression);
}
catch (Exception e) {
logger.error("Failed to delete documents by filter: {}", e.getMessage(), e);
Expand All @@ -353,21 +353,19 @@ public List<Document> doSimilaritySearch(SearchRequest request) {
String jsonPathFilter = "";

if (StringUtils.hasText(nativeFilterExpression)) {
jsonPathFilter = "and " + nativeFilterExpression + " ";
jsonPathFilter = "and ? ";
}
String distanceType = this.distanceType.name().toLowerCase(Locale.ROOT);

double distance = 1 - request.getSimilarityThreshold();
final String sql = String.format(
"SELECT * FROM (select %s, %s, %s, vec_distance_%s(%s, ?) as distance "
+ "from %s) as t where distance < ? %sorder by distance asc LIMIT ?",
this.idFieldName, this.contentFieldName, this.metadataFieldName, distanceType, this.embeddingFieldName,
getFullyQualifiedTableName(), jsonPathFilter);
final String sql = "SELECT * FROM (select ?, ?, ?, vec_distance_?(?, ?) as distance "
+ "from ?) as t where distance < ? ?order by distance asc LIMIT ?";

logger.debug("SQL query: {}", sql);

return this.jdbcTemplate.query(sql, new DocumentRowMapper(this.objectMapper), embedding, distance,
request.getTopK());
return this.jdbcTemplate.query(sql, new DocumentRowMapper(this.objectMapper), this.idFieldName,
this.contentFieldName, this.metadataFieldName, distanceType, this.embeddingFieldName,
getFullyQualifiedTableName(), jsonPathFilter, embedding, distance, request.getTopK());
}

// ---------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ protected void doDelete(Filter.Expression filterExpression) {

try {
String jsonPath = this.filterExpressionConverter.convertExpression(filterExpression);
String sql = String.format("DELETE FROM %s WHERE JSON_EXISTS(metadata, '%s')", this.tableName, jsonPath);
String sql = "DELETE FROM ? WHERE JSON_EXISTS(metadata, '?')";

logger.debug("Executing delete with filter: {}", sql);
logger.debug("Executing delete with filter: {} with params: {} {}", sql, this.tableName, jsonPath);

int deletedCount = this.jdbcTemplate.update(sql);
int deletedCount = this.jdbcTemplate.update(sql, this.tableName, jsonPath);
logger.debug("Deleted {} documents matching filter expression", deletedCount);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,11 @@ public int getBatchSize() {
protected void doDelete(Filter.Expression filterExpression) {
String nativeFilterExpression = this.filterExpressionConverter.convertExpression(filterExpression);

String sql = "DELETE FROM " + getFullyQualifiedTableName() + " WHERE metadata::jsonb @@ '"
+ nativeFilterExpression + "'::jsonpath";
String sql = "DELETE FROM ? WHERE metadata::jsonb @@ '?'::jsonpath";

// Execute the delete
try {
this.jdbcTemplate.update(sql);
this.jdbcTemplate.update(sql, getFullyQualifiedTableName(), nativeFilterExpression);
}
catch (Exception e) {
throw new IllegalStateException("Failed to delete documents by filter", e);
Expand Down