켈 경고 : 이 SDK는 여전히 알파 상태에 있습니다. 그것이 주로 구축되고 기능적이지만 UX를 계속 개선함에 따라 변화를 겪을 수 있습니다. 시도해보고 피드백을주십시오. 그러나 업데이트로 인해 변경 사항이 발생할 수 있습니다.
문서는 여기에서 찾을 수 있습니다.
Rust 버전 : Rust 버전 1.78.0으로 테스트
Pinecone SDK를 사용하기 전에 계정에 가입하고 https://app.pinecone.io (https://app.pinecone.io)에서 API 키를 찾아야합니다.
cargo add pinecone-sdk 크레이트를 의존성으로 추가하거나 [dependencies] 의 Cargo.toml 파일에 라인 pinecone-sdk = "0.1.2" 추가하십시오. 상자에 대한 자세한 내용은 여기에서 찾을 수 있습니다.
PineconeClient 클래스는 Rust SDK에 진입하는 주요 지점입니다. 매개 변수는 Options 으로 직접 전달되거나 다음과 같이 환경 변수를 통해 읽을 수 있습니다. 자세한 내용 :
PINECONE_API_KEY 라는 환경 변수로 전달되어야합니다. None 으로 통과하면 클라이언트는 환경 변수 값으로 읽으려고 시도합니다.None 통과하면 PINECONE_CONTROLLER_HOST 라는 환경 변수에서 읽으려고 시도합니다. 환경 변수가 아닌 경우 https://api.pinecone.io 로 기본값을받습니다.아래에 자세히 설명하는 몇 가지 방법이 있습니다.
매개 변수로 PineconeClientConfig Struct를 초기화하고 Struct를 사용하여 config 호출하십시오.
use pinecone_sdk :: pinecone :: { PineconeClient , PineconeClientConfig } ;
let config = PineconeClientConfig {
api_key : Some ( "INSERT_API_KEY" . to_string ( ) ) ,
control_plane_host : Some ( "INSERT_CONTROLLER_HOST" . to_string ( ) ) ,
.. Default :: default ( )
} ;
let pinecone : PineconeClient = config . client ( ) . expect ( "Failed to create Pinecone instance" ) ; 모든 필드가 None 으로 설정된 default_client() struct PineconeClientConfig 구성하는 것과 같습니다. API 키 및 제어 평면 호스트 (선택 사항)는 환경 변수에서 읽습니다.
let pinecone : PineconeClient = pinecone_sdk :: pinecone :: default_client ( ) . expect ( "Failed to create Pinecone instance" ) ; 다음 예제는 us-east-1 AWS 영역에서 서버리스 인덱스를 만듭니다. 서버리스 및 지역 가용성에 대한 자세한 내용은 인덱스 이해를 참조하십시오.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Metric , Cloud , WaitPolicy , IndexModel } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . create_serverless_index (
"index-name" , // Name of the index
10 , // Dimension of the vectors
Metric :: Cosine , // Distance metric
Cloud :: Aws , // Cloud provider
"us-east-1" , // Region
WaitPolicy :: NoWait // Timeout
) . await ? ; 다음 예제는 us-east-1 영역에서 AWS의 POD 지수를 만듭니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Metric , Cloud , WaitPolicy , IndexModel } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . create_pod_index (
"index-name" , // Index name
10 , // Dimension
Metric :: Cosine , // Distance metric
"us-east-1" , // Region
"p1.x1" , // Pod type
1 , // Number of pods
None , // Number of replicas
None , // Number of shards
None , // Metadata to index
None , // Source collection
WaitPolicy :: NoWait // Wait policy
) . await ? ;POD 인덱스는 여러 선택적 구성 필드를 지원합니다. 다음 예제는 이러한 필드에 대한 일부 사양이있는 POD 인덱스를 구성합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Metric , Cloud , WaitPolicy , IndexModel } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . create_pod_index (
"index-name" , // Index name
10 , // Dimension
Metric :: Cosine , // Distance metric
"us-east-1" , // Region
"p1.x1" , // Pod type
1 , // Number of pods
Some ( 1 ) , // Number of replicas
Some ( 1 ) , // Number of shards
Some ( // Metadata fields to index
& vec ! [ "genre" ,
"title" ,
"imdb_rating" ] ) ,
Some ( "collection" ) , // Source collection
WaitPolicy :: NoWait // Wait policy
) . await ? ; 다음 예제는 프로젝트의 모든 색인을 나열합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: IndexList ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_list : IndexList = pinecone . list_indexes ( ) . await ? ; 다음 예제는 색인 index-name 에 대한 정보를 반환합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: IndexModel ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . describe_index ( "index-name" ) . await ? ; 인덱스 구성은 3 가지 선택적 매개 변수 (deletionprotection enum, 복제본 수 및 POD 유형)를 사용합니다. 삭제 보호는 모든 인덱스 유형에 대해 업데이트 될 수 있으며 복제본 수와 포드 유형은 POD 인덱스에 대해서만 업데이트 될 수 있습니다.
다음 예제는 인덱스 index-name 에 대한 삭제 보호를 비활성화합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: IndexModel ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . configure_index ( "index-name" , Some ( DeletionProtection :: Disabled ) , None , None ) . await ? ; 다음 예제는 6 개의 복제본과 POD 유형 s1 이 있도록 색인 index-name 변경합니다. 이 경우 삭제 보호 유형은 변경되지 않습니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: IndexModel ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let index_description : IndexModel = pinecone . configure_index ( "index-name" , None , Some ( 6 ) , Some ( "s1" ) ) . await ? ; 다음 예제는 인덱스 index-name 삭제합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
pinecone . delete_index ( "index-name" ) . await ? ; 다음 예제는 호스트 index-host 와 인덱스에 대한 통계를 반환합니다. 필터없이
use std :: collections :: BTreeMap ;
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: DescribeIndexStatsResponse ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let response : DescribeIndexStatsResponse = index . describe_index_stats ( None ) . await ? ;필터로
use std :: collections :: BTreeMap ;
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Value , Kind , Metadata , DescribeIndexStatsResponse } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let mut fields = BTreeMap :: new ( ) ;
let kind = Some ( Kind :: StringValue ( "value" . to_string ( ) ) ) ;
fields . insert ( "field" . to_string ( ) , Value { kind } ) ;
let response : DescribeIndexStatsResponse = index . describe_index_stats ( Some ( Metadata { fields } ) ) . await ? ; 다음 예제는 호스트 index-host 사용하여 두 벡터를 인덱스로 향상시킵니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Vector , UpsertResponse } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let vectors = [ Vector {
id : "id1" . to_string ( ) ,
values : vec ! [ 1.0 , 2.0 , 3.0 , 4.0 ] ,
sparse_values : None ,
metadata : None ,
} , Vector {
id : "id2" . to_string ( ) ,
values : vec ! [ 2.0 , 3.0 , 4.0 , 5.0 ] ,
sparse_values : None ,
metadata : None ,
} ] ;
let response : UpsertResponse = index . upsert ( & vectors , & "namespace" . into ( ) ) . await ? ; 인덱스를 쿼리하는 두 가지 지원 방법이 있습니다.
다음 예제는 ID vector-id 사용하여 벡터의 호스트 index-host 로 인덱스를 쿼리하고 상위 10 개 일치를 반환합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Namespace , QueryResponse } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
// Connect to index at host "index-host"
let mut index = pinecone . index ( "index-host" ) . await ? ;
// Query the vector with id "vector-id" in the namespace "namespace"
let response : QueryResponse = index . query_by_id (
"vector-id" . to_string ( ) ,
10 ,
& Namespace :: default ( ) ,
None ,
None ,
None
) . await ? ; 다음 예제는 값 [1.0, 2.0, 3.0, 4.0] 을 가진 벡터의 호스트 index-host 로 인덱스를 쿼리하고 상위 10 개 일치를 반환합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Namespace , QueryResponse } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let vector = vec ! [ 1.0 , 2.0 , 3.0 , 4.0 ] ;
let response : QueryResponse = index . query_by_value (
vector ,
None ,
10 ,
& Namespace :: default ( ) ,
None ,
None ,
None
) . await ? ; 벡터를 삭제하는 세 가지 지원 방법이 있습니다.
다음 예제는 네임 스페이스 namespace 에서 ID vector-id 로 벡터를 삭제합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let ids = [ "vector-id" ]
index . delete_by_id ( & ids , & "namespace" . into ( ) ) . await ? ; 다음 예제는 네임 스페이스 namespace 에서 필터를 만족시키는 벡터를 삭제합니다.
use std :: collections :: BTreeMap ;
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Metadata , Value , Kind , Namespace } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut fields = BTreeMap :: new ( ) ;
let kind = Some ( Kind :: StringValue ( "value" . to_string ( ) ) ) ;
fields . insert ( "field" . to_string ( ) , Value { kind } ) ;
index . delete_by_filter ( Metadata { fields } , & "namespace" . into ( ) ) . await ? ; 다음 예제는 네임 스페이스 namespace 에서 모든 벡터를 삭제합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
index . delete_all ( & "namespace" . into ( ) ) . await ? ; 다음 예제는 기본 네임 스페이스에서 ID 1 과 2 로 벡터를 가져옵니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: FetchResponse ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let vectors = & [ "1" , "2" ] ;
let response : FetchResponse = index . fetch ( vectors , & Default :: default ( ) ) . await ? ; 다음 예제는 네임 스페이스 namespace 에 ID vector-id 로 벡터를 업데이트하여 값을 갖도록 [1.0, 2.0, 3.0, 4.0] .
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: UpdateResponse ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let response : UpdateResponse = index . update ( "vector-id" , vec ! [ 1.0 , 2.0 , 3.0 , 4.0 ] , None , None , & "namespace" . into ( ) ) . await ? ; 다음 예제는 네임 스페이스 namespace 의 벡터를 나열합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: { Namespace , ListResponse } ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let mut index = pinecone . index ( "index-host" ) . await ? ;
let response : ListResponse = index . list ( & "namespace" . into ( ) , None , None , None ) . await ? ; 다음 예제는 인덱스 index-name 에서 컬렉션 collection-name 만듭니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: CollectionModel ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let collection : CollectionModel = pinecone . create_collection ( "collection-name" , "index-name" ) . await ? ; 다음 예제는 프로젝트의 모든 컬렉션을 나열합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: CollectionList ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let collection_list : CollectionList = pinecone . list_collections ( ) . await ? ; 다음 예제는 컬렉션 collection-name 설명합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
use pinecone_sdk :: models :: CollectionModel ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
let collection : CollectionModel = pinecone . describe_collection ( "collection-name" ) . await ? ; 다음 예제는 컬렉션 collection-name 삭제합니다.
use pinecone_sdk :: pinecone :: PineconeClientConfig ;
let config = PineconeClientConfig {
api_key : Some ( ' << PINECONE_API_KEY >> ' ) ,
.. Default :: default ( )
} ;
let pinecone = config . client ( ) ? ;
pinecone . delete_collection ( "collection-name" ) . await ? ;Pinecone Rust 클라이언트를 개발하기 위해 기부금을하거나 로컬로 설정하려면 기고 가이드를 참조하십시오.