@@ -139,20 +139,49 @@ public static void insertIntoVectorize(String id, BigDecimal[] vector, String ch
139
139
outputStream .flush ();
140
140
}
141
141
142
- System .out .println ("(Vectorize) Upsert request returned status " + con .getResponseCode ());
142
+ System .out .println ("(Vectorize: Upsert) Request returned status " + con .getResponseCode ());
143
143
try (var inputStream = con .getResponseCode () < HttpURLConnection .HTTP_BAD_REQUEST ? con .getInputStream () : con .getErrorStream ();
144
144
var reader = new InputStreamReader (inputStream )) {
145
145
StringBuilder responseBuilder = new StringBuilder ();
146
146
int c ;
147
147
while ((c = reader .read ()) != -1 ) {
148
148
responseBuilder .append ((char ) c );
149
149
}
150
- System .out .println ("(Vectorize) Response body: " + responseBuilder );
150
+ System .out .println ("(Vectorize: Upsert ) Response body: " + responseBuilder );
151
151
}
152
152
153
-
153
+ }
154
154
155
-
155
+ public static void deleteFromVectorize (String id ) throws IOException {
156
+ final String token = System .getenv ("CF_TOKEN" );
157
+ if (token == null || token .isEmpty ()) throw new IOException ("Missing CF Token!" );
158
+
159
+ URL url = new URL ("https://api.cloudflare.com/client/v4/accounts/f55b85c8a963663b11036975203c63c0/vectorize/v2/indexes/support-autoresponse/delete_by_ids" );
160
+ HttpURLConnection con = (HttpURLConnection ) url .openConnection ();
161
+ con .setRequestMethod ("POST" );
162
+ con .setRequestProperty ("Content-Type" , "application/json" );
163
+ con .setRequestProperty ("Authorization" , "Bearer " + token ); // Replace YOUR_BEARER_TOKEN with your actual token
164
+ con .setDoOutput (true );
165
+
166
+ String payload = String .format (
167
+ "{\" ids\" : [\" %s\" ]}" ,
168
+ id
169
+ );
170
+ try (var outputStream = con .getOutputStream ()) {
171
+ outputStream .write (payload .getBytes ());
172
+ outputStream .flush ();
173
+ }
174
+
175
+ System .out .println ("(Vectorize: Delete) Request returned status " + con .getResponseCode ());
176
+ try (var inputStream = con .getResponseCode () < HttpURLConnection .HTTP_BAD_REQUEST ? con .getInputStream () : con .getErrorStream ();
177
+ var reader = new InputStreamReader (inputStream )) {
178
+ StringBuilder responseBuilder = new StringBuilder ();
179
+ int c ;
180
+ while ((c = reader .read ()) != -1 ) {
181
+ responseBuilder .append ((char ) c );
182
+ }
183
+ System .out .println ("(Vectorize: Delete) Response body: " + responseBuilder );
184
+ }
156
185
}
157
186
158
187
public static class VectorizeResponse {
0 commit comments