이것은 PineconeVectorService 및 PineconeIndexService라는 두 가지 편리한 서비스로 제공되는 모든 사용 가능한 색인, 벡터, 컬렉션, 추론 및 보조 작업/엔드 포인트를 지원하는 Pinecone API 용 직관적 인 비동기 본격 스칼라 클라이언트입니다. 지원되는 통화는 다음과 같습니다.
PineconeAssistantService 및 PineconeAssistantFileService PENECONE API 이름과 일치하려면 서비스 기능 이름이 API 엔드 포인트 제목/설명과 Camelcase와 정확히 일치합니다. 또한, 우리는 LIB가 가능한 가장 적은 의존성에 독립적 인 것을 목표로 삼았으므로 결국 두 개의 LIBS play-ahc-ws-standalone 과 play-ws-standalone-json (최상위) 만 사용했습니다.
✔️ 중요한 : 이것은 "커뮤니티 관리 된"도서관이므로 Pinecone Company와 관련이 없습니다.
Medium의 LIB/Client에 대한 기사를 확인하십시오. 또한 실습 예제를 즉시 보려면 Pinecone 예제 또는 OpenAi + Pinecone 예제 모듈로 이동하십시오.
현재 지원되는 스칼라 버전은 2.12, 2.13 및 3 입니다.
라이브러리를 당기려면 다음의 종속성을 Build.sbt 에 추가해야합니다.
"io.cequence" %% "pinecone-scala-client" % "1.2.2"
또는 pom.xml 에 (Maven을 사용하는 경우)
<dependency>
<groupId>io.cequence</groupId>
<artifactId>pinecone-scala-client_2.12</artifactId>
<version>1.2.2</version>
</dependency>
PINECONE_SCALA_CLIENT_API_KEY 및 POD 기반 서비스가 사용되는 경우 PINECONE_SCALA_CLIENT_ENV ia. PineconeIndexService 획득
먼저 암시 적 실행 컨텍스트와 AKKA Materializer와 같은
implicit val ec = ExecutionContext .global
implicit val materializer = Materializer ( ActorSystem ())그런 다음 다음 방법 중 하나로 서비스 (POD 또는 Serverless 기반)를 얻을 수 있습니다.
Config 섹션에 정의 된대로 설정할 Env. 변수 예상) import io . cequence . pineconescala . service . PineconeIndexServiceFactory . FactoryImplicits
val service = PineconeIndexServiceFactory ().asOne val config = ConfigFactory .load( " path_to_my_custom_config " )
val service = PineconeIndexServiceFactory (config).asOnePineconePodBasedIndexService 인스턴스를 만듭니다. val service = PineconeIndexServiceFactory (
apiKey = " your_api_key " ,
environment = " your_env " // e.g. "northamerica-northeast1-gcp
)PineconeServerlessIndexService 인스턴스를 만듭니다. val service = PineconeIndexServiceFactory (
apiKey = " your_api_key "
) ib. PineconeVectorService 획득
PineconeIndexService 와 마찬가지로 먼저 암시 적 실행 컨텍스트 및 AKKA Materializer를 제공해야합니다. 그런 다음 다음 방법 중 하나로 서비스를 얻을 수 있습니다.
Config 섹션에 정의 된대로 설정할 Env. 변수를 기대 함). 주어진 이름이있는 인덱스를 사용할 수 없으면 공장은 None 반환하지 않습니다. PineconeVectorServiceFactory ( " index_name " ).map { serviceOption =>
val service = serviceOption.getOrElse(
throw new Exception ( s " Index with a given name does not exist. " )
)
// do something with the service
} IC. PineconeInferenceService 획득
PineconeIndexService 와 마찬가지로 먼저 암시 적 실행 컨텍스트 및 AKKA Materializer를 제공해야합니다. 그런 다음 다음 방법 중 하나로 서비스를 얻을 수 있습니다.
val service = PineconeInferenceServiceFactory () val config = ConfigFactory .load( " path_to_my_custom_config " )
val service = PineconeInferenceServiceFactory (config) val service = PineconeInferenceServiceFactory (
apiKey = " your_api_key "
) ID. PineconeAssistantService 획득
val service = PineconeAssistantServiceFactory () val config = ConfigFactory .load( " path_to_my_custom_config " )
val service = PineconeAssistantServiceFactory (config) val service = PineconeAssistantServiceFactory (
apiKey = " your_api "
) 즉. PineconeAssistantFileService 획득
val service = PineconeAssistantFileServiceFactory () val config = ConfigFactory .load( " path_to_my_custom_config " )
val service = PineconeAssistantFileServiceFactory (config) val service = PineconeAssistantFileServiceFactory (
apiKey = " your_api "
)II. 호출 기능
각각의 입력 및 설정이있는 각 통화의 전체 문서는 PineconeVectorService 및 PineconeIndexService에 제공됩니다. 모든 통화는 비동기이기 때문에 Future 랩핑 된 응답을 반환합니다.
예 :
인덱스 작업
pineconeIndexService.listIndexes.map(indexes =>
indexes.foreach(println)
) import io . cequence . pineconescala . domain . response . CreateResponse
pineconeIndexService.createIndex(
name = " auto-gpt-test " ,
dimension = 1536
).map {
case CreateResponse . Created => println( " Index successfully created. " )
case CreateResponse . BadRequest => println( " Index creation failed. Request exceeds quota or an invalid index name. " )
case CreateResponse . AlreadyExists => println( " Index with a given name already exists. " )
} pineconeIndexService.describeIndex( " index_name " ).map(indexInfo =>
// if not found, indexInfo will be None
println(indexInfo)
) import io . cequence . pineconescala . domain . response . DeleteResponse
pineconeIndexService.deleteIndex( " index_name " ).map {
case DeleteResponse . Deleted => println( " Index successfully deleted. " )
case DeleteResponse . NotFound => println( " Index with a given name not found. " )
} import io . cequence . pineconescala . domain . response . ConfigureIndexResponse
pineconeIndexService.configureIndex(
name = " index_name " ,
replicas = Some ( 2 ),
pod_type = Some ( PodType .p1_x2)
).map {
case ConfigureIndexResponse . Updated => println( " Index successfully updated. " )
case ConfigureIndexResponse . BadRequestNotEnoughQuota => println( " Index update failed. Not enough quota. " )
case ConfigureIndexResponse . NotFound => println( " Index with a given name not found. " )
}수집 작업
pineconeIndexService.listCollections.map(collectionNames =>
println(collectionNames.mkString( " , " ))
) import io . cequence . pineconescala . domain . response . CreateResponse
pineconeIndexService.createCollection(
name = " collection_name " ,
source = " index_name "
).map {
case CreateResponse . Created => println( " Collection successfully created. " )
case CreateResponse . BadRequest => println( " Collection creation failed. Request exceeds quota or an invalid collection name. " )
case CreateResponse . AlreadyExists => println( " Collection with a given name already exists. " )
} pineconeIndexService.describeCollection( " collection_name " ).map(collectionInfo =>
// if not found, collectionInfo will be None
println(collectionInfo)
) import io . cequence . pineconescala . domain . response . DeleteResponse
pineconeIndexService.deleteCollection( " collection_name " ).map {
case DeleteResponse . Deleted => println( " Collection successfully deleted. " )
case DeleteResponse . NotFound => println( " Collection with a given name not found. " )
}벡터 작동
val dimension = 1536
pineconeVectorService.upsert(
vectors = Seq (
PVector (
id = " 666 " ,
values = Seq .fill(dimension)( Random .nextDouble),
metadata = Map (
" is_relevant " -> " not really but for testing it's ok, you know " ,
" food_quality " -> " brunches are perfect but don't go there before closing time "
)
),
PVector (
id = " 777 " ,
values = Seq .fill(dimension)( Random .nextDouble),
metadata = Map (
" is_relevant " -> " very much so " ,
" food_quality " -> " burritos are the best! "
)
)
),
namespace = " my_namespace " ,
).map(vectorUpsertedCount =>
println( s " Upserted $vectorUpsertedCount vectors. " )
) val fetchedValues = ... // vectors fetched from somewhere
pineconeVectorService.update(
id = " 777 " ,
namespace = " my_namespace " ,
values = fetchedValues.map(_ / 100 ), // divide fetched values by 100
sparseValues = Some ( SparseVector (
indices = Seq ( 1 , 2 , 3 ),
values = Seq ( 8.8 , 7.7 , 2.2 )
)),
setMetaData = Map (
" solid_info " -> " this is the source of the truth "
)
).map(_ =>
println( s " Vectors updated. " )
) pineconeVectorService.query(
vector = Seq .fill( 1536 )( Random .nextDouble), // some values/embeddings
namespace = " my_namespace "
).map { queryResponse =>
queryResponse.matches.foreach { matchInfo =>
println( s " Matched vector id: ${matchInfo.id} " )
println( s " Matched vector values: ${matchInfo.values.take( 20 ).mkString( " , " )} .. " )
println( s " Matched vector score: ${matchInfo.score} " )
println( s " Matched vector metadata: ${matchInfo.metadata} " )
}
} pineconeVectorService.query(
vector = Seq .fill( 1536 )( Random .nextDouble), // some values/embeddings
namespace = " my_namespace " ,
settings = QuerySettings (
topK = 5 ,
includeValues = true ,
includeMetadata = true
)
).map { queryResponse =>
queryResponse.matches.foreach { matchInfo =>
println( s " Matched vector id: ${matchInfo.id} " )
println( s " Matched vector values: ${matchInfo.values.take( 20 ).mkString( " , " )} .. " )
println( s " Matched vector score: ${matchInfo.score} " )
println( s " Matched vector metadata: ${matchInfo.metadata} " )
}
} pineconeVectorService.fetch(
ids = Seq ( " 666 " , " 777 " ),
namespace = " my_namespace "
).map { fetchResponse =>
fetchResponse.vectors.values.map { pVector =>
println( s " Fetched vector id: ${pVector.id} " )
println( s " Fetched vector values: ${pVector.values.take( 20 ).mkString( " , " )} .. " )
println( s " Fetched vector metadata: ${pVector.metadata} " )
}
} pineconeVectorService.delete(
ids = Seq ( " 666 " , " 777 " ),
namespace = " my_namespace "
).map(_ =>
println( " Vectors deleted " )
) pineconeVectorService.deleteAll(
namespace = " my_namespace "
).map(_ =>
println( " All vectors deleted " )
) pineconeVectorService.describeIndexStats.map(stats =>
println(stats)
)추론 운영
pineconeInferenceService.createEmbeddings(
Seq ( " The quick brown fox jumped over the lazy dog " )
).map { embeddings =>
println(embeddings.data.mkString( " n " ))
} pineconeInferenceService.rerank(
query = " The tech company Apple is known for its innovative products like the iPhone. " ,
documents = Seq (...)
).map(
_.data.foreach(println)
) pineconeInferenceService.evaluate(
question = " What are the capital cities of France, England and Spain? " ,
answer = " Paris is a city of France and Barcelona of Spain " ,
groundTruthAnswer = " Paris is the capital city of France, London of England and Madrid of Spain "
).map { response =>
println(response)
}** 보조 작업 **
pineconeAssistantService.listAssistants.map(assistants =>
println(assistants.mkString( " , " ))
) import io . cequence . pineconescala . domain . response . CreateResponse
pineconeAssistantService.createAssistant(
name = " assistant_name " ,
description = " assistant_description " ,
assistantType = " assistant_type "
).map {
case CreateResponse . Created => println( " Assistant successfully created. " )
case CreateResponse . BadRequest => println( " Assistant creation failed. Request exceeds quota or an invalid assistant name. " )
case CreateResponse . AlreadyExists => println( " Assistant with a given name already exists. " )
} pineconeAssistantService.describeAssistant( " assistant_name " ).map(assistant =>
// if not found, assistant will be None
println(assistant)
) import io . cequence . pineconescala . domain . response . DeleteResponse
pineconeAssistantService.deleteAssistant( " assistant_name " ).map {
case DeleteResponse . Deleted => println( " Assistant successfully deleted. " )
case DeleteResponse . NotFound => println( " Assistant with a given name not found. " )
} pineconeAssistantService.listFiles( " assistant_name " ).map(files =>
println(files.mkString( " , " ))
) import io . cequence . pineconescala . domain . response . CreateResponse
pineconeAssistantService.uploadFile(
assistantName = " assistant_name " ,
filePath = " path_to_file "
).map {
case CreateResponse . Created => println( " File successfully uploaded. " )
case CreateResponse . BadRequest => println( " File upload failed. Request exceeds quota or an invalid file path. " )
case CreateResponse . AlreadyExists => println( " File with a given name already exists. " )
} pineconeAssistantService.describeFile( " assistant_name " , " file_name " ).map(file =>
// if not found, file will be None
println(file)
) pineconeAssistantService.chatWithAssistant(
" assistant_name " ,
" What is the maximum height of a red pine? "
).map(response =>
println(response)
)즉시 실행되는 데모 PL. 별도의 모듈을 참조하십시오.
타임 아웃 예외가 있습니다. 타임 아웃 설정을 어떻게 변경할 수 있습니까?
timeouts Param을 Pinecone{Vector,Index}ServiceFactory 로 전달하거나 자신의 구성 파일을 사용하는 경우 다음과 같이 추가 할 수 있습니다.
pinecone-scala-client {
timeouts {
requestTimeoutSec = 200
readTimeoutSec = 200
connectTimeoutSec = 5
pooledConnectionIdleTimeoutSec = 60
}
}
com.typesafe.config.ConfigException$UnresolvedSubstitution: pinecone-scala-client.conf @ jar:file:.../io/cequence/pinecone-scala-client_2.13/1.2.2/pinecone-scala-client_2.13-1.2.2.jar!/pinecone-scala-client.conf: 4: Could not resolve substitution to a value: ${PINECONE_SCALA_CLIENT_API_KEY} . 어떻게해야하나요?
ENV를 설정하십시오. 변수 PINECONE_SCALA_CLIENT_API_KEY . 여기에 등록이 하나없는 경우.
모두 멋져 보입니다. 귀하의 연구 개발에 대해 이야기하고 싶습니다.
[email protected]에서 이메일을 촬영하십시오.
이 라이브러리는 MIT 라이센스의 조건에 따라 오픈 소스로 제공되고 게시됩니다.
이 프로젝트는 오픈 소스이며 모든 기여 또는 피드백을 환영합니다 (여기).
이 도서관의 개발은 -cequence.io- The future of contracting 의해 지원되었습니다.
Peter Banda가 창조하고 유지합니다.