|
| 1 | +use pinecone_sdk::pinecone::data::Namespace; |
| 2 | +use rand::Rng; |
| 3 | + |
| 4 | +/// Generates a random string of length 10 |
| 5 | +pub fn generate_random_string() -> String { |
| 6 | + use rand::distributions::Alphanumeric; |
| 7 | + use rand::{thread_rng, Rng}; |
| 8 | + |
| 9 | + let s: String = thread_rng() |
| 10 | + .sample_iter(&Alphanumeric) |
| 11 | + .take(10) |
| 12 | + .map(char::from) |
| 13 | + .collect(); |
| 14 | + |
| 15 | + s.to_lowercase() |
| 16 | +} |
| 17 | + |
| 18 | +/// Generates a random index name |
| 19 | +pub fn generate_index_name() -> String { |
| 20 | + format!("test-index-{}", generate_random_string()) |
| 21 | +} |
| 22 | + |
| 23 | +/// Generates a random collection name |
| 24 | +pub fn generate_collection_name() -> String { |
| 25 | + format!("test-collection-{}", generate_random_string()) |
| 26 | +} |
| 27 | + |
| 28 | +/// Generates a random namespace name |
| 29 | +pub fn generate_namespace_name() -> Namespace { |
| 30 | + let name = format!("test-namespace-{}", generate_random_string()); |
| 31 | + name.into() |
| 32 | +} |
| 33 | + |
| 34 | +/// Generates a random vector of length `length` |
| 35 | +pub fn generate_vector(length: usize) -> Vec<f32> { |
| 36 | + let mut rng = rand::thread_rng(); |
| 37 | + (0..length).map(|_| rng.gen()).collect() |
| 38 | +} |
| 39 | + |
| 40 | +/// Returns the name of the serverless index from the environment variable |
| 41 | +pub fn get_serverless_index() -> String { |
| 42 | + std::env::var("SERVERLESS_INDEX_NAME").unwrap() |
| 43 | +} |
| 44 | + |
| 45 | +/// Returns the name of the pod collection from the environment variable |
| 46 | +pub fn get_pod_index() -> String { |
| 47 | + std::env::var("POD_INDEX_NAME").unwrap() |
| 48 | +} |
| 49 | + |
| 50 | +/// Returns the name of the collection from the environment variable |
| 51 | +pub fn get_collection() -> String { |
| 52 | + std::env::var("COLLECTION_NAME").unwrap() |
| 53 | +} |
0 commit comments