Skip to content

Commit cb2b8ac

Browse files
committed
cache sqlite statement for linker embeddings lookup
1 parent ae13c59 commit cb2b8ac

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

dataload/linker/src/main/java/Embeddings.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class Embeddings {
1616

1717
private Connection connection;
1818
private Gson gson;
19+
private PreparedStatement stmt;
1920

2021
public Embeddings() {
2122
this.gson = new Gson();
@@ -28,10 +29,15 @@ public void loadEmbeddingsFromFile(String sqlitePath) throws IOException {
2829
config.setReadOnly(true);
2930
config.setOpenMode(SQLiteOpenMode.READONLY);
3031
this.connection = DriverManager.getConnection("jdbc:sqlite:" + sqlitePath, config.toProperties());
32+
this.stmt = this.connection.prepareStatement(
33+
"SELECT embeddings FROM embeddings WHERE ontologyId = ? AND entityType = ? AND iri = ?"
34+
);
35+
3136
} catch (SQLException e) {
3237
e.printStackTrace();
3338
return;
3439
}
40+
3541
}
3642

3743
public double[] getEmbeddings(String ontologyId, String entityType, String iri) {
@@ -42,12 +48,10 @@ public double[] getEmbeddings(String ontologyId, String entityType, String iri)
4248

4349
try {
4450

45-
var stmt = this.connection.prepareStatement("SELECT embeddings FROM embeddings WHERE ontologyId = ? AND entityType = ? AND iri = ?");
46-
47-
stmt.setString(1, ontologyId);
48-
stmt.setString(2, entityType);
49-
stmt.setString(3, iri);
50-
var rs = stmt.executeQuery();
51+
this.stmt.setString(1, ontologyId);
52+
this.stmt.setString(2, entityType);
53+
this.stmt.setString(3, iri);
54+
var rs = this.stmt.executeQuery();
5155
if (rs.next()) {
5256
String embeddingString = rs.getString("embeddings");
5357

0 commit comments

Comments
 (0)