Skip to content

Commit 40972a4

Browse files
committed
Fix mariadb similarity search
- The similarity search doesn't need the embedding to be returned/stored back to Document
1 parent 99a44fb commit 40972a4

File tree

1 file changed

+5
-9
lines changed
  • vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb

1 file changed

+5
-9
lines changed

vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ public List<Document> doSimilaritySearch(SearchRequest request) {
421421

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

429429
logger.debug("SQL query: " + sql);
430430

@@ -536,15 +536,11 @@ public Document mapRow(ResultSet rs, int rowNum) throws SQLException {
536536
String id = rs.getString(1);
537537
String content = rs.getString(2);
538538
Map<String, Object> metadata = toMap(rs.getString(3));
539-
float[] embedding = rs.getObject(4, float[].class);
540-
float distance = rs.getFloat(5);
539+
float distance = rs.getFloat(4);
541540

542541
metadata.put("distance", distance);
543542

544-
Document document = new Document(id, content, metadata);
545-
document.setEmbedding(embedding);
546-
547-
return document;
543+
return new Document(id, content, metadata);
548544
}
549545

550546
private Map<String, Object> toMap(String source) {

0 commit comments

Comments
 (0)