Add getNativeClient API to VectorStore interface

Adds getNativeClient API to VectorStore interface allowing access to the underlying native client implementation.

This change:
- Adds getNativeClient() default method to VectorStore interface returning Optional<T>
- Implements getNativeClient() in all vector store implementations exposing their respective native clients
- Adds integration tests verifying native client access for all implementations

Fixes: #2137

Signed-off-by: Soby Chacko <soby.chacko@broadcom.com>
This commit is contained in:
Soby Chacko
2025-02-02 15:20:33 -05:00
committed by Mark Pollack
parent 54463e6622
commit 16a596f8b7
53 changed files with 618 additions and 2 deletions

View File

@@ -476,6 +476,13 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini
return SIMILARITY_TYPE_MAPPING.get(this.distanceType).value();
}
@Override
public <T> Optional<T> getNativeClient() {
@SuppressWarnings("unchecked")
T client = (T) this.jdbcTemplate;
return Optional.of(client);
}
/**
* By default, pgvector performs exact nearest neighbor search, which provides perfect
* recall. You can add an index to use approximate nearest neighbor search, which

View File

@@ -482,6 +482,15 @@ public class PgVectorStoreIT {
});
}
@Test
void getNativeClientTest() {
this.contextRunner.run(context -> {
PgVectorStore vectorStore = context.getBean(PgVectorStore.class);
Optional<JdbcTemplate> nativeClient = vectorStore.getNativeClient();
assertThat(nativeClient).isPresent();
});
}
@SpringBootConfiguration
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public static class TestApplication {