Skip to content

Commit e90d293

Browse files
authored
Change parameters from String to &str (#43)
## Problem One of the parameters for `fetch` was `&[String]` instead of `&[&str]`. Similarly, one of the parameters for `query_by_id` was `String` instead of `&str`. ## Solution I changed the parameter types to `&[&str]` and `&str` respectively for consistency with other functions. I also updated all relevant code. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan Test cases should pass.
1 parent e1d5544 commit e90d293

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

codegen/apis

Submodule apis updated from d1c2230 to 4de4456

pinecone_sdk/src/pinecone/data.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Index {
293293
/// The query operation searches a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.
294294
///
295295
/// ### Arguments
296-
/// * `id: String` - The id of the query vector.
296+
/// * `id: &str` - The id of the query vector.
297297
/// * `top_k: u32` - The number of results to return.
298298
/// * `namespace: &Namespace` - The namespace to query. Default is "".
299299
/// * `filter: Option<Metadata>` - The filter to apply to limit your search by vector metadata.
@@ -317,21 +317,21 @@ impl Index {
317317
/// let mut index = pinecone.index("index-host").await.unwrap();
318318
///
319319
/// // Query the vector with id "vector-id" in the namespace "namespace"
320-
/// let response = index.query_by_id("vector-id".to_string(), 10, &Namespace::default(), None, None, None).await.unwrap();
320+
/// let response = index.query_by_id("vector-id", 10, &Namespace::default(), None, None, None).await.unwrap();
321321
/// # Ok(())
322322
/// # }
323323
/// ```
324324
pub async fn query_by_id(
325325
&mut self,
326-
id: String,
326+
id: &str,
327327
top_k: u32,
328328
namespace: &Namespace,
329329
filter: Option<Metadata>,
330330
include_values: Option<bool>,
331331
include_metadata: Option<bool>,
332332
) -> Result<QueryResponse, PineconeError> {
333333
let request = pb::QueryRequest {
334-
id,
334+
id: id.to_string(),
335335
top_k,
336336
namespace: namespace.name.clone(),
337337
filter,
@@ -547,7 +547,7 @@ impl Index {
547547
/// The fetch operation retrieves vectors by ID from a namespace.
548548
///
549549
/// ### Arguments
550-
/// * `ids: &[String]` - The ids of vectors to fetch.
550+
/// * `ids: &[&str]` - The ids of vectors to fetch.
551551
/// * `namespace: &Namespace` - The namespace to fetch vectors from. Default is "".
552552
///
553553
/// ### Return
@@ -567,7 +567,7 @@ impl Index {
567567
/// // Connect to index host url
568568
/// let mut index = pinecone.index("index-host").await.unwrap();
569569
///
570-
/// let vectors = &["1".to_string(), "2".to_string()];
570+
/// let vectors = &["1", "2"];
571571
///
572572
/// // Fetch vectors from the default namespace that have the ids in the list
573573
/// let response = index.fetch(vectors, &Default::default()).await.unwrap();
@@ -576,11 +576,12 @@ impl Index {
576576
/// ```
577577
pub async fn fetch(
578578
&mut self,
579-
ids: &[String],
579+
ids: &[&str],
580580
namespace: &Namespace,
581581
) -> Result<FetchResponse, PineconeError> {
582+
let ids = ids.iter().map(|id| id.to_string()).collect::<Vec<String>>();
582583
let request = pb::FetchRequest {
583-
ids: ids.to_vec(),
584+
ids,
584585
namespace: namespace.name.clone(),
585586
};
586587

pinecone_sdk/tests/integration_test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ async fn test_query_by_id() -> Result<(), PineconeError> {
649649
.expect("Failed to target index");
650650

651651
let _query_response = index
652-
.query_by_id("1".to_string(), 10, &Namespace::default(), None, None, None)
652+
.query_by_id("1", 10, &Namespace::default(), None, None, None)
653653
.await
654654
.expect("Failed to query");
655655

@@ -983,7 +983,7 @@ async fn test_fetch_vectors() -> Result<(), PineconeError> {
983983

984984
let fetch_response = index
985985
.fetch(
986-
&["1".to_string(), "2".to_string()],
986+
&["1", "2"],
987987
namespace,
988988
)
989989
.await
@@ -1034,7 +1034,7 @@ async fn test_fetch_no_match() -> Result<(), PineconeError> {
10341034
.expect("Failed to target index");
10351035

10361036
let fetch_response = index
1037-
.fetch(&["invalid-id1".to_string(), "invalid-id2".to_string()], &Default::default())
1037+
.fetch(&["invalid-id1", "invalid-id2"], &Default::default())
10381038
.await
10391039
.expect("Failed to fetch vectors");
10401040

0 commit comments

Comments
 (0)