pinecone_rs/lib.rs
1//! This crate allows you to connect and interact with Pinecone, the vector database. After
2//! authenticating you're api key and you're environment key, this crate facilitates the connection
3//! to a pinecone index. Once a connection has been validated this API allows you to upsert,
4//! query, and update data within Pinecone as well more unmentioned commands. More details about
5//! the different api methods can be found [here](https://docs.pinecone.io/reference/describe_index_stats_post)
6//!
7//! This crate currently only supports the http / rest pinecone api and does not support GRCP. GRCP
8//! will be implemented into the future as opt in. Http is currently the default
9//!
10//! To connect, initalize a [`Client`] using the [`Client::new`] method. This is an asynchronous
11//! operation that will also validate you're credentials and will error if invalid credentials are
12//! given. You can then run operations on you're client / account using the methods on [`Client`]
13//! or create a new [`Index`] via the [`Client::index`] method. This index will not be validated
14//! intially, it can be validated by calling the [`Index::describe`] method which will attempt to
15//! get information about the index and subsequently validate the credentials if it goes through
16//! successfully.
17//!
18//! Below is a basic client and index example.
19//!```no_run
20//!use pinenut::{Client, models::Vector};
21//!
22//!async fn index_upsert() {
23//!
24//! // We create an instance of client first and firstmost. Panics if it couldn't authenticate.
25//! let client = Client::new(env!("PINECONE_API_KEY"), env!("PINECONE_ENV")).await.unwrap();
26//! // creates an index, will not authenticate.
27//! let mut index = client.index(env!("PINECONE_INDEX_NAME"));
28//!
29//! // We use describe as a form of authenticate, panicing if we couldn't authenticate.
30//! let _ = index.describe().await.unwrap();
31//! let vec = Vector{
32//! id: "B".to_string(),
33//! values: vec![0.5; 32],
34//! sparse_values: None,
35//! metadata: None
36//! };
37//!
38//! match index.upsert(String::from("odle"), vec![vec]).await {
39//! Ok(_) => assert!(true),
40//! Err(err) => panic!("unable to upsert: {:?}", err)
41//! }
42//!}
43//!```
44//!
45//!
46//!
47
48#![deny(missing_docs)]
49#![warn(rust_2018_idioms)]
50
51macro_rules! if_rest {
52 ($($item:item)*) => {$(
53 #[cfg(feature="rest")]
54 $item
55 )*}
56}
57
58//TODO: create macro for GRCP when that becomes implemented
59
60if_rest! {
61 mod rest;
62 pub use self::rest::{models, Client, Index};
63}
64
65pub mod error;
66pub use crate::error::{Error, Result};