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 @@ -319,12 +319,21 @@ private Object convertIdToPgType(String id) {

@Override
public void doDelete(List<String> idList) {
int updateCount = 0;
for (String id : idList) {
int count = this.jdbcTemplate.update("DELETE FROM " + getFullyQualifiedTableName() + " WHERE id = ?",
UUID.fromString(id));
updateCount = updateCount + count;
}
String sql = "DELETE FROM " + getFullyQualifiedTableName() + " WHERE id = ?";

this.jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
var id = idList.get(i);
StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, convertIdToPgType(id));
}

@Override
public int getBatchSize() {
return idList.size();
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
* @author Christian Tzolov
* @author Thomas Vitale
* @author Jihoon Kim
* @author CChuYong
*/
@Testcontainers
@EnabledIfEnvironmentVariable(named = "OPENAI_API_KEY", matches = ".+")
Expand Down Expand Up @@ -232,6 +233,47 @@ public void testToPgTypeWithNonUuidIdType() {
});
}

@Test
public void testBulkOperationWithUuidIdType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test. This test runs fine when running as a standalone but fails when all the tests within this class run. Looks like some race condition there. Could you check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review!
i figured out that getNativeClientTest also initializes vector table, so i also added code for dropping table in getNativeClientTest. fb829af

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix!

this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.pgvector.distanceType=" + "COSINE_DISTANCE")
.run(context -> {

VectorStore vectorStore = context.getBean(VectorStore.class);

List<Document> documents = List.of(
new Document(new RandomIdGenerator().generateId(), "TEXT", new HashMap<>()),
new Document(new RandomIdGenerator().generateId(), "TEXT", new HashMap<>()),
new Document(new RandomIdGenerator().generateId(), "TEXT", new HashMap<>()));
vectorStore.add(documents);

List<String> idList = documents.stream().map(Document::getId).toList();
vectorStore.delete(idList);

dropTable(context);
});
}

@Test
public void testBulkOperationWithNonUuidIdType() {
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.pgvector.distanceType=" + "COSINE_DISTANCE")
.withPropertyValues("test.spring.ai.vectorstore.pgvector.initializeSchema=" + false)
.withPropertyValues("test.spring.ai.vectorstore.pgvector.idType=" + "TEXT")
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
initSchema(context);

List<Document> documents = List.of(new Document("NON_UUID_1", "TEXT", new HashMap<>()),
new Document("NON_UUID_2", "TEXT", new HashMap<>()),
new Document("NON_UUID_3", "TEXT", new HashMap<>()));
vectorStore.add(documents);

List<String> idList = documents.stream().map(Document::getId).toList();
vectorStore.delete(idList);

dropTable(context);
});
}

@ParameterizedTest(name = "Filter expression {0} should return {1} records ")
@MethodSource("provideFilters")
public void searchWithInFilter(String expression, Integer expectedRecords) {
Expand Down Expand Up @@ -436,6 +478,8 @@ void getNativeClientTest() {
PgVectorStore vectorStore = context.getBean(PgVectorStore.class);
Optional<JdbcTemplate> nativeClient = vectorStore.getNativeClient();
assertThat(nativeClient).isPresent();

dropTable(context);
});
}

Expand Down