Skip to content

Commit

Permalink
Randomize namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamon committed Oct 4, 2023
1 parent a862aca commit f779747
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.primitives.Floats;
import com.google.protobuf.Struct;
import com.google.protobuf.Value;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.model.IndexMeta;
import io.pinecone.proto.*;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void sanity() throws Exception {
new PineconeConnectionConfig()
.withConnectionUrl("https://" + host));

String ns = "temp_namespace";
String ns = RandomStringBuilder.build("ns", 8);

// upsert
float[][] upsertData = {{1.0F, 2.0F, 3.0F}, {4.0F, 5.0F, 6.0F}, {7.0F, 8.0F, 9.0F}};
Expand Down Expand Up @@ -154,7 +155,7 @@ public void sanity() throws Exception {
// Query by id example
QueryRequest queryByIdRequest = QueryRequest.newBuilder()
.setId("v2")
.setNamespace("temp_namespace")
.setNamespace(ns)
.setTopK(2)
.setIncludeMetadata(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.pinecone.PineconeClientConfig;
import io.pinecone.PineconeIndexOperationClient;
import io.pinecone.helpers.RandomStringBuilder;
import io.pinecone.model.CreateIndexRequest;
import io.pinecone.model.IndexMeta;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -25,20 +26,9 @@ public void setUp() throws Exception {
pinecone = new PineconeIndexOperationClient(config);
}

protected String getRandomIndexName(int len) {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
StringBuilder name = new StringBuilder();
Random rnd = new Random();
while (name.length() < len) {
int index = (int) (rnd.nextFloat() * alphabet.length());
name.append(alphabet.charAt(index));
}
return "test-index-" + name.toString();
}

@Test
public void createAndDelete() throws IOException {
String indexName = getRandomIndexName(8);
String indexName = RandomStringBuilder.build("index-name", 8);

// Create an index
CreateIndexRequest request = new CreateIndexRequest()
Expand Down
16 changes: 16 additions & 0 deletions src/integration/java/io/pinecone/helpers/RandomStringBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.pinecone.helpers;

import java.util.Random;

public class RandomStringBuilder {
public static String build(String prefix, int len) {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
StringBuilder name = new StringBuilder();
Random rnd = new Random();
while (name.length() < len) {
int index = (int) (rnd.nextFloat() * alphabet.length());
name.append(alphabet.charAt(index));
}
return prefix + "-" + name.toString();
}
}

0 comments on commit f779747

Please sign in to comment.