Skip to content

Commit a6d2437

Browse files
committed
cutting a release
1 parent f17e6f1 commit a6d2437

16 files changed

+166
-160
lines changed

astra-sdk-vector/pom.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
<artifactId>lombok</artifactId>
2727
</dependency>
2828

29-
<!-- Help creating index -->
30-
<dependency>
31-
<groupId>com.datastax.oss</groupId>
32-
<artifactId>java-driver-query-builder</artifactId>
33-
</dependency>
34-
3529
<dependency>
3630
<groupId>com.datastax.astra</groupId>
3731
<artifactId>astra-sdk</artifactId>
@@ -41,6 +35,22 @@
4135
<groupId>com.datastax.astra</groupId>
4236
<artifactId>astra-sdk-pulsar</artifactId>
4337
</exclusion>
38+
<exclusion>
39+
<groupId>com.datastax</groupId>
40+
<artifactId>astra-sdk-pulsar</artifactId>
41+
</exclusion>
42+
<exclusion>
43+
<groupId>com.datastax.stargate</groupId>
44+
<artifactId>stargate-sdk-document</artifactId>
45+
</exclusion>
46+
<exclusion>
47+
<groupId>com.datastax.stargate</groupId>
48+
<artifactId>stargate-sdk-graphql</artifactId>
49+
</exclusion>
50+
<exclusion>
51+
<groupId>com.datastax.stargate</groupId>
52+
<artifactId>stargate-sdk-grpc</artifactId>
53+
</exclusion>
4454
</exclusions>
4555
</dependency>
4656

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/cassio/AbstractCassandraTable.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import com.datastax.oss.driver.api.core.CqlSession;
44
import com.datastax.oss.driver.api.core.cql.Row;
5-
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
6-
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
75

86
import java.util.concurrent.CompletableFuture;
97

108
/**
119
* Abstract class for table management at Cassandra level.
10+
*
11+
* @param <RECORD>
12+
* object in use with Cassandra
1213
*/
1314
public abstract class AbstractCassandraTable<RECORD> {
1415

@@ -121,19 +122,14 @@ public CompletableFuture<Void> putAsync(final RECORD inputRow) {
121122
* Delete the table.
122123
*/
123124
public void delete() {
124-
cqlSession.execute(SchemaBuilder
125-
.dropTable(keyspaceName, tableName)
126-
.ifExists()
127-
.build());
125+
cqlSession.execute("DROP TABLE IF EXISTS " + keyspaceName + "." + tableName);
128126
}
129127

130128
/**
131129
* Empty a table
132130
*/
133131
public void clear() {
134-
cqlSession.execute(QueryBuilder
135-
.truncate(keyspaceName, tableName)
136-
.build());
132+
cqlSession.execute("TRUNCATE " + keyspaceName + "." + tableName);
137133
}
138134

139135
}

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/cassio/ClusteredCassandraTable.java

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
import com.datastax.oss.driver.api.core.cql.BatchType;
77
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
88
import com.datastax.oss.driver.api.core.cql.Row;
9-
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
10-
import com.datastax.oss.driver.api.core.type.DataTypes;
11-
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
12-
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
139
import lombok.AllArgsConstructor;
1410
import lombok.Data;
1511
import lombok.NoArgsConstructor;
@@ -49,36 +45,34 @@ public class ClusteredCassandraTable extends AbstractCassandraTable<ClusteredCas
4945
public ClusteredCassandraTable(@NonNull CqlSession session, @NonNull String keyspaceName, @NonNull String tableName) {
5046
super(session, keyspaceName, tableName);
5147
createSchema();
52-
findPartitionStatement = session.prepare(QueryBuilder.selectFrom(tableName).all()
53-
.whereColumn(PARTITION_ID).isEqualTo(QueryBuilder.bindMarker())
54-
.build());
55-
deletePartitionStatement = session.prepare(QueryBuilder.deleteFrom(tableName)
56-
.whereColumn(PARTITION_ID).isEqualTo(QueryBuilder.bindMarker())
57-
.build());
58-
findRowStatement = session.prepare(QueryBuilder.selectFrom(tableName).all()
59-
.whereColumn(PARTITION_ID).isEqualTo(QueryBuilder.bindMarker())
60-
.whereColumn(ROW_ID).isEqualTo(QueryBuilder.bindMarker())
61-
.build());
62-
deleteRowStatement = session.prepare(QueryBuilder.deleteFrom(tableName)
63-
.whereColumn(PARTITION_ID).isEqualTo(QueryBuilder.bindMarker())
64-
.whereColumn(ROW_ID).isEqualTo(QueryBuilder.bindMarker())
65-
.build());
66-
insertRowStatement = session.prepare(QueryBuilder.insertInto(tableName)
67-
.value(PARTITION_ID, QueryBuilder.bindMarker())
68-
.value(ROW_ID, QueryBuilder.bindMarker())
69-
.value(BODY_BLOB, QueryBuilder.bindMarker())
70-
.build());
48+
findPartitionStatement = session.prepare(
49+
"select * from " + keyspaceName + "." + tableName
50+
+ " where " + PARTITION_ID + " = ? ");
51+
deletePartitionStatement = session.prepare(
52+
"delete from " + keyspaceName + "." + tableName
53+
+ " where " + PARTITION_ID + " = ? ");
54+
findRowStatement = session.prepare(
55+
"select * from " + keyspaceName + "." + tableName
56+
+ " where " + PARTITION_ID + " = ? "
57+
+ " and " + ROW_ID + " = ? ");
58+
deleteRowStatement = session.prepare(
59+
"delete from " + keyspaceName + "." + tableName
60+
+ " where " + PARTITION_ID + " = ? "
61+
+ " and " + ROW_ID + " = ? ");
62+
insertRowStatement = session.prepare(
63+
"insert into " + keyspaceName + "." + tableName
64+
+ " (" + PARTITION_ID + ", " + ROW_ID + ", " + BODY_BLOB + ") "
65+
+ " values (?, ?, ?)");
7166
}
7267

7368
@Override
7469
public void createSchema() {
75-
cqlSession.execute(SchemaBuilder.createTable(tableName)
76-
.ifNotExists()
77-
.withPartitionKey(PARTITION_ID, DataTypes.TEXT)
78-
.withClusteringColumn(ROW_ID, DataTypes.TIMEUUID)
79-
.withColumn(BODY_BLOB, DataTypes.TEXT)
80-
.withClusteringOrder(ROW_ID, ClusteringOrder.DESC)
81-
.build());
70+
cqlSession.execute("CREATE TABLE IF NOT EXISTS " + keyspaceName + "." + tableName + " ("
71+
+ PARTITION_ID + " text, "
72+
+ ROW_ID + " timeuuid, "
73+
+ BODY_BLOB + " text, "
74+
+ "PRIMARY KEY ((" + PARTITION_ID + "), " + ROW_ID + ")) "
75+
+ "WITH CLUSTERING ORDER BY (" + ROW_ID + " DESC");
8276
log.info("+ Table '{}' has been created (if needed).", tableName);
8377
}
8478

@@ -181,17 +175,13 @@ public void delete(@NonNull String partitionId, @NonNull UUID rowId) {
181175
* body
182176
*/
183177
public void insert(@NonNull String partitionId, @NonNull UUID rowId, @NonNull String bodyBlob) {
184-
cqlSession.execute(QueryBuilder.insertInto(keyspaceName, tableName)
185-
.value(PARTITION_ID, QueryBuilder.literal(partitionId))
186-
.value(ROW_ID, QueryBuilder.literal(rowId))
187-
.value(BODY_BLOB, QueryBuilder.literal(bodyBlob))
188-
.build());
178+
cqlSession.execute(insertRowStatement.bind(partitionId,rowId, bodyBlob));
189179
}
190180

191181
/**
192182
* Represents a row of the Table
193183
*/
194-
@Data @AllArgsConstructor @NoArgsConstructor
184+
@Data @AllArgsConstructor
195185
public static class Record {
196186

197187
/** Partition id. */
@@ -202,6 +192,12 @@ public static class Record {
202192

203193
/** Text body. */
204194
private String body;
195+
196+
/**
197+
* Default constructor
198+
*/
199+
public Record() {
200+
}
205201
}
206202

207203

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/cassio/MetadataVectorCassandraTable.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
66
import com.datastax.oss.driver.api.core.data.CqlVector;
77
import com.datastax.oss.driver.api.core.uuid.Uuids;
8-
import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
9-
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
10-
import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert;
11-
import lombok.Builder;
128
import lombok.Data;
139
import lombok.Getter;
1410
import lombok.extern.slf4j.Slf4j;
@@ -83,21 +79,17 @@ public void createSchema() {
8379
// Create Vector Index
8480
Map<String, Object> optionMap = new HashMap<>();
8581
optionMap.put("similarity_function", similarityMetric.getOption());
86-
cqlSession.execute(SchemaBuilder.createIndex("idx_vector_" + tableName)
87-
.ifNotExists()
88-
.custom(SAI_INDEX_CLASSNAME)
89-
.onTable(tableName)
90-
.andColumn(VECTOR)
91-
.withSASIOptions(optionMap)
92-
.build());
82+
cqlSession.execute(
83+
"CREATE CUSTOM INDEX IF NOT EXISTS idx_vector_" + tableName
84+
+ " ON " + tableName + " (" + VECTOR + ") "
85+
+ "USING 'org.apache.cassandra.index.sai.StorageAttachedIndex' "
86+
+ "WITH OPTIONS = " + optionMap.toString());
9387
log.info("+ Index '{}' has been created (if needed).", "idx_vector_" + tableName);
9488
// Create Metadata Index
95-
cqlSession.execute(SchemaBuilder.createIndex("eidx_metadata_s_" + tableName)
96-
.ifNotExists()
97-
.custom(SAI_INDEX_CLASSNAME)
98-
.onTable(tableName)
99-
.andColumnEntries(METADATA_S)
100-
.build());
89+
cqlSession.execute(
90+
"CREATE CUSTOM INDEX IF NOT EXISTS eidx_metadata_s_" + tableName
91+
+ " ON " + tableName + " ENTRIES(" + METADATA_S + ") "
92+
+ "USING 'org.apache.cassandra.index.sai.StorageAttachedIndex' ");
10193
log.info("+ Index '{}' has been created (if needed).", "eidx_metadata_s_" + tableName);
10294
}
10395

@@ -248,20 +240,9 @@ public Record(String rowId, List<Float> vector) {
248240
public SimpleStatement insertStatement(String keyspaceName, String tableName) {
249241
if (rowId == null) throw new IllegalStateException("Row Id cannot be null");
250242
if (vector == null) throw new IllegalStateException("Vector cannot be null");
251-
RegularInsert insert = QueryBuilder
252-
.insertInto(keyspaceName, tableName)
253-
.value(ROW_ID, QueryBuilder.literal(rowId))
254-
.value(VECTOR, QueryBuilder.literal(CqlVector.newInstance(vector)));
255-
if (attributes != null) {
256-
insert = insert.value(ATTRIBUTES_BLOB, QueryBuilder.literal(attributes));
257-
}
258-
if (body != null) {
259-
insert = insert.value(BODY_BLOB, QueryBuilder.literal(body));
260-
}
261-
if (metadata != null && !metadata.isEmpty()) {
262-
insert = insert.value(METADATA_S, QueryBuilder.literal(metadata));
263-
}
264-
return insert.build();
243+
return SimpleStatement.newInstance("INSERT INTO " + keyspaceName + "." + tableName + " ("
244+
+ ROW_ID + "," + VECTOR + "," + ATTRIBUTES_BLOB + "," + BODY_BLOB + "," + METADATA_S + ") VALUES (?,?,?,?,?)",
245+
rowId, CqlVector.newInstance(vector), attributes, body, metadata);
265246
}
266247
}
267248
}

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/cassio/SimilarityMetric.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
@Getter
99
public enum SimilarityMetric {
1010

11+
/** dot product. */
1112
DOT_PRODUCT("DOT_PRODUCT","similarity_dot_product"),
1213

14+
/** cosine. */
1315
COS("COSINE","similarity_cosine"),
1416

17+
/** euclidean. */
1518
DOT("EUCLIDEAN","similarity_euclidean");
1619

1720
/**

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/vector/AstraVectorClient.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ public UUID createDatabase(@NonNull String name) {
151151
*
152152
* @param name
153153
* database name
154+
* @param cloud
155+
* cloud provider
154156
* @param cloudRegion
155157
* cloud region
156158
* @return
@@ -207,12 +209,18 @@ public Stream<Database> findByName(String name) {
207209
return findAllDatabases().filter(db->name.equals(db.getInfo().getName()));
208210
}
209211

212+
/**
213+
* Check if a database exists.
214+
*
215+
* @param name
216+
* a database name
217+
* @return
218+
* list of db matching the criteria
219+
*/
210220
public boolean isDatabaseExists(String name) {
211221
return findByName(name).findFirst().isPresent();
212222
}
213223

214-
215-
216224
/**
217225
* Find a database from its id.
218226
*
@@ -285,6 +293,13 @@ private void waitForDatabase(DatabaseClient dbc) {
285293
}
286294
}
287295

296+
/**
297+
* Retrieve the status of a database.
298+
* @param dbc
299+
* database client
300+
* @return
301+
* database status
302+
*/
288303
private DatabaseStatusType getStatus(DatabaseClient dbc) {
289304
return dbc.find().orElseThrow(() -> new DatabaseNotFoundException(dbc.getDatabaseId())).getStatus();
290305
}

astra-sdk-vector/src/main/java/com/dtsx/astra/sdk/vector/AstraVectorDatabaseClient.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ public class AstraVectorDatabaseClient {
3434
*/
3535
private final JsonNamespaceClient nsClient;
3636

37+
/**
38+
* Full constructor.
39+
*
40+
* @param token
41+
* token
42+
* @param databaseId
43+
* datbase identifier
44+
* @param env
45+
* environment
46+
*/
3747
public AstraVectorDatabaseClient(@NonNull String token, @NonNull UUID databaseId, @NonNull AstraEnvironment env) {
3848
this.env = env;
3949

@@ -88,7 +98,7 @@ public void deleteStore(String name) {
8898
*
8999
* @param name
90100
* store name
91-
* param dimension
101+
* @param dimension
92102
* vector dimension
93103
* @param metric
94104
* metric for the similarity
@@ -102,8 +112,10 @@ public void createVectorStore(String name, int dimension, SimilarityMetric metri
102112
*
103113
* @param name
104114
* store name
105-
* param dimension
115+
* @param dimension
106116
* dimension
117+
* @return
118+
* json vector store
107119
*/
108120
public JsonVectorStore createVectorStore(String name, int dimension) {
109121
nsClient.createCollection(name, dimension);
@@ -115,8 +127,14 @@ public JsonVectorStore createVectorStore(String name, int dimension) {
115127
*
116128
* @param name
117129
* store name
118-
* param dimension
130+
* @param dimension
119131
* dimension
132+
* @param bean
133+
* class of pojo
134+
* @return
135+
* vector store instance
136+
* @param <T>
137+
* object type
120138
*/
121139
public <T> VectorStore<T> createVectorStore(String name, int dimension, Class<T> bean) {
122140
nsClient.createCollection(name, dimension);
@@ -162,8 +180,12 @@ public JsonVectorStore vectorStore(@NonNull String storeName) {
162180
*
163181
* @param storeName
164182
* store identifier
183+
* @param clazz
184+
* type of object used
165185
* @return
166186
* storeName client
187+
* @param <T>
188+
* type of the bean in use
167189
*/
168190
public <T> VectorStore<T> vectorStore(@NonNull String storeName, Class<T> clazz) {
169191
return nsClient.vectorStore(storeName, clazz);

0 commit comments

Comments
 (0)