Skip to content

Commit f0c05d8

Browse files
committed
WS client version bump (0.4.0)
1 parent c4fec24 commit f0c05d8

File tree

10 files changed

+92
-134
lines changed

10 files changed

+92
-134
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pinecone Scala Client 🗂️
2-
[![version](https://img.shields.io/badge/version-0.1.2-green.svg)](https://cequence.io) [![License](https://img.shields.io/badge/License-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT) ![GitHub Stars](https://img.shields.io/github/stars/cequence-io/pinecone-scala?style=social) [![Twitter Follow](https://img.shields.io/twitter/follow/0xbnd?style=social)](https://twitter.com/0xbnd)
2+
[![version](https://img.shields.io/badge/version-0.1.3-green.svg)](https://cequence.io) [![License](https://img.shields.io/badge/License-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT) ![GitHub Stars](https://img.shields.io/github/stars/cequence-io/pinecone-scala?style=social) [![Twitter Follow](https://img.shields.io/twitter/follow/0xbnd?style=social)](https://twitter.com/0xbnd)
33

44
This is an intuitive async Scala client for Pinecone API supporting all the available vector and index/collection operations/endpoints, provided in two convenient services called [PineconeVectorService](./pinecone-core/src/main/scala/io/cequence/pineconescala/service/PineconeVectorService.scala) and [PineconeIndexService](./pinecone-core/src/main/scala/io/cequence/pineconescala/service/PineconeIndexService.scala). The supported calls are:
55

@@ -22,7 +22,7 @@ The currently supported Scala versions are **2.12, 2.13**, and **3**.
2222
To pull the library you have to add the following dependency to your *build.sbt*
2323

2424
```
25-
"io.cequence" %% "pinecone-scala-client" % "0.1.2"
25+
"io.cequence" %% "pinecone-scala-client" % "0.1.3"
2626
```
2727

2828
or to *pom.xml* (if you use maven)
@@ -31,7 +31,7 @@ or to *pom.xml* (if you use maven)
3131
<dependency>
3232
<groupId>io.cequence</groupId>
3333
<artifactId>pinecone-scala-client_2.12</artifactId>
34-
<version>0.1.2</version>
34+
<version>0.1.3</version>
3535
</dependency>
3636
```
3737

@@ -428,7 +428,7 @@ pinecone-scala-client {
428428
}
429429
```
430430

431-
2. _I got an exception like `com.typesafe.config.ConfigException$UnresolvedSubstitution: pinecone-scala-client.conf @ jar:file:.../io/cequence/pinecone-scala-client_2.13/0.1.2/pinecone-scala-client_2.13-0.1.2.jar!/pinecone-scala-client.conf: 4: Could not resolve substitution to a value: ${PINECONE_SCALA_CLIENT_API_KEY}`. What should I do?_
431+
2. _I got an exception like `com.typesafe.config.ConfigException$UnresolvedSubstitution: pinecone-scala-client.conf @ jar:file:.../io/cequence/pinecone-scala-client_2.13/0.1.3/pinecone-scala-client_2.13-0.1.3.jar!/pinecone-scala-client.conf: 4: Could not resolve substitution to a value: ${PINECONE_SCALA_CLIENT_API_KEY}`. What should I do?_
432432

433433
Set the env. variable `PINECONE_SCALA_CLIENT_API_KEY`. If you don't have one register [here](https://app.pinecone.io/?sessionType=signup).
434434

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ val scala33 = "3.3.1"
88

99
ThisBuild / organization := "io.cequence"
1010
ThisBuild / scalaVersion := scala212
11-
ThisBuild / version := "0.1.2"
11+
ThisBuild / version := "0.1.3"
1212
ThisBuild / isSnapshot := false
1313

1414
lazy val core = (project in file("pinecone-core"))

pinecone-client/build.sbt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,11 @@ import Dependencies.Versions._
22

33
name := "pinecone-scala-client"
44

5-
description := "Scala client for Pinecone API implemented with Play WS lib."
5+
libraryDependencies ++= Seq(
6+
"io.cequence" %% "ws-client-core" % wsClient,
7+
"io.cequence" %% "ws-client-play" % wsClient,
68

7-
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.18"
8-
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.18" % Test
9-
libraryDependencies += "org.scalatestplus" %% "mockito-4-11" % "3.2.18.0" % Test
10-
11-
libraryDependencies += "io.cequence" %% "ws-client-core" % wsClient
12-
libraryDependencies += "io.cequence" %% "ws-client-play" % wsClient
13-
14-
lazy val playWsVersion = settingKey[String]("Play WS version")
15-
inThisBuild(
16-
playWsVersion := {
17-
scalaVersion.value match {
18-
case "2.12.18" => "2.1.10"
19-
case "2.13.11" => "2.2.0-M3"
20-
case "3.2.2" =>
21-
"2.2.0-M2" // Version "2.2.0-M3" was produced by an unstable release: Scala 3.3.0-RC3
22-
case _ => "2.1.10"
23-
}
24-
}
9+
"org.scalactic" %% "scalactic" % "3.2.18",
10+
"org.scalatest" %% "scalatest" % "3.2.18" % Test,
11+
"org.scalatestplus" %% "mockito-4-11" % "3.2.18.0" % Test
2512
)
26-
27-
libraryDependencies += "com.typesafe.play" %% "play-ws-standalone-json" % playWsVersion.value

pinecone-client/src/main/scala/io/cequence/pineconescala/service/EndPoint.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.cequence.pineconescala.service
22

33
import io.cequence.pineconescala.domain.settings.IndexSettings.{CreatePodBasedIndexSettings, CreateServerlessIndexSettings}
4-
import io.cequence.wsclient.domain.{EnumValue, NamedEnumValue}
4+
import io.cequence.wsclient.domain.NamedEnumValue
55

66
sealed abstract class EndPoint(value: String = "") extends NamedEnumValue(value)
77

@@ -54,10 +54,8 @@ object Tag {
5454
case object spec extends Tag
5555
case object shards extends Tag
5656
case object inputs extends Tag
57-
case object input_type extends Tag
5857
case object model extends Tag
5958
case object parameters extends Tag
60-
case object truncate extends Tag
6159

6260
// TODO: move elsewhere
6361
def fromCreatePodBasedIndexSettings(

pinecone-client/src/main/scala/io/cequence/pineconescala/service/PineconeIndexServiceImpl.scala

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import io.cequence.pineconescala.domain.settings.IndexSettings.{
1313
import io.cequence.pineconescala.domain.settings._
1414
import io.cequence.pineconescala.domain.{Metric, PodType}
1515
import io.cequence.wsclient.JsonUtil.JsonOps
16-
import io.cequence.wsclient.domain.WsRequestContext
16+
import io.cequence.wsclient.ResponseImplicits._
17+
import io.cequence.wsclient.domain.{RichResponse, WsRequestContext}
1718
import io.cequence.wsclient.service.ws.{Timeouts, WSRequestHelper}
1819
import play.api.libs.json.JsValue
19-
import play.api.libs.ws.StandaloneWSRequest
2020

2121
import scala.concurrent.{ExecutionContext, Future}
2222

@@ -59,7 +59,7 @@ private final class ServerlessIndexServiceImpl(
5959
dimension: Int,
6060
settings: CreateServerlessIndexSettings
6161
): Future[CreateResponse] =
62-
execPOSTWithStatus(
62+
execPOSTRich(
6363
indexesEndpoint,
6464
bodyParams = {
6565
jsonBodyParams(
@@ -120,7 +120,7 @@ private final class PineconePodPineconeBasedImpl(
120120
dimension: Int,
121121
settings: CreatePodBasedIndexSettings
122122
): Future[CreateResponse] =
123-
execPOSTWithStatus(
123+
execPOSTRich(
124124
indexesEndpoint,
125125
bodyParams = jsonBodyParams(
126126
Tag.fromCreatePodBasedIndexSettings(name, dimension, settings): _*
@@ -133,21 +133,22 @@ private final class PineconePodPineconeBasedImpl(
133133
replicas: Option[Int],
134134
podType: Option[PodType]
135135
): Future[ConfigureIndexResponse] =
136-
execPATCHWithStatus(
136+
execPATCRich(
137137
indexesEndpoint,
138138
endPointParam = Some(indexName),
139139
bodyParams = jsonBodyParams(
140140
Tag.replicas -> replicas,
141141
Tag.pod_type -> podType.map(_.toString)
142142
)
143-
).map { response =>
144-
val (statusCode, message) = statusCodeAndMessage(response)
143+
).map { richResponse =>
144+
val status = richResponse.status
145145

146-
statusCode match {
146+
status.code match {
147147
case 202 => ConfigureIndexResponse.Updated
148148
case 400 => ConfigureIndexResponse.BadRequestNotEnoughQuota
149149
case 404 => ConfigureIndexResponse.NotFound
150-
case _ => throw new PineconeScalaClientException(s"Code ${statusCode} : ${message}")
150+
case _ =>
151+
throw new PineconeScalaClientException(s"Code ${status.code} : ${status.message}")
151152
}
152153
}
153154

@@ -165,7 +166,7 @@ private final class PineconePodPineconeBasedImpl(
165166
name: String,
166167
source: String
167168
): Future[CreateResponse] =
168-
execPOSTWithStatus(
169+
execPOSTRich(
169170
EndPoint.collections,
170171
bodyParams = jsonBodyParams(
171172
Tag.name -> Some(name),
@@ -175,7 +176,8 @@ private final class PineconePodPineconeBasedImpl(
175176
).map(handleCreateResponse)
176177

177178
override def listCollections: Future[Seq[String]] =
178-
execGET(EndPoint.collections).map(response => response.asSafe[Seq[String]]
179+
execGET(EndPoint.collections).map(
180+
_.asSafeJson[Seq[String]]
179181
// response
180182
// .asSafe[Seq[String]](response \ "collections")
181183
// .asOpt[Seq[JsValue]]
@@ -206,41 +208,44 @@ abstract class PineconeIndexServiceImpl[S <: IndexSettings](
206208
override protected type PEP = EndPoint
207209
override protected type PT = Tag
208210

209-
override protected val requestContext = WsRequestContext(explTimeouts = explicitTimeouts)
211+
override protected val requestContext = WsRequestContext(
212+
authHeaders = Seq(("Api-Key", apiKey)),
213+
explTimeouts = explicitTimeouts
214+
)
210215

211216
def isPodBasedIndex: Boolean = environment.isDefined
212217
def isServerlessIndex: Boolean = !isPodBasedIndex
213218

214219
override def describeCollection(
215220
collectionName: String
216221
): Future[Option[CollectionInfo]] =
217-
execGETWithStatus(
222+
execGETRich(
218223
EndPoint.collections,
219224
endPointParam = Some(collectionName)
220225
).map { response =>
221226
handleNotFoundAndError(response).map(
222-
_.asSafe[CollectionInfo]
227+
_.asSafeJson[CollectionInfo]
223228
)
224229
}
225230

226231
override def deleteCollection(
227232
collectionName: String
228233
): Future[DeleteResponse] =
229-
execDELETEWithStatus(
234+
execDELETERich(
230235
EndPoint.collections,
231236
endPointParam = Some(collectionName),
232237
acceptableStatusCodes = Nil // don't parse response at all
233238
).map(handleDeleteResponse)
234239

235240
override def listIndexes: Future[Seq[String]] =
236241
execGET(indexesEndpoint).map(response =>
237-
(response \ "indexes")
242+
(response.json \ "indexes")
238243
.asOpt[Seq[JsValue]]
239244
.map(indexes => {
240245
indexes.flatMap(index => (index \ "name").asOpt[String])
241246
})
242247
.getOrElse(
243-
response.asSafe[Seq[String]]
248+
response.asSafeJson[Seq[String]]
244249
)
245250
)
246251

@@ -249,17 +254,19 @@ abstract class PineconeIndexServiceImpl[S <: IndexSettings](
249254
override def describeIndex(
250255
indexName: String
251256
): Future[Option[IndexInfo]] =
252-
execGETWithStatus(
257+
execGETRich(
253258
indexesEndpoint,
254259
endPointParam = Some(indexName)
255-
).map { response: RichJsResponse =>
256-
handleNotFoundAndError(response).map(describeIndexResponse)
260+
).map { richResponse: RichResponse =>
261+
handleNotFoundAndError(richResponse).map(response =>
262+
describeIndexResponse(response.json)
263+
)
257264
}
258265

259266
override def deleteIndex(
260267
indexName: String
261268
): Future[DeleteResponse] =
262-
execDELETEWithStatus(
269+
execDELETERich(
263270
indexesEndpoint,
264271
endPointParam = Some(indexName),
265272
acceptableStatusCodes = Nil // don't parse response at all
@@ -271,25 +278,6 @@ abstract class PineconeIndexServiceImpl[S <: IndexSettings](
271278
// otherwise (serverless arch) we use indexes endpoint
272279
protected def indexesEndpoint: PEP // Either[EndPoint.databases.type, EndPoint.indexes.type]
273280

274-
// TODO: remove this and use WsRequestContext instead
275-
override protected def addHeaders(request: StandaloneWSRequest): StandaloneWSRequest = {
276-
val apiKeyHeader = ("Api-Key", apiKey)
277-
request.addHttpHeaders(apiKeyHeader)
278-
}
279-
280-
protected def statusCodeAndMessage(
281-
response: RichJsResponse
282-
): (Int, String) =
283-
response match {
284-
case Right(statusCodeAndMessage) => statusCodeAndMessage
285-
286-
// should never happen
287-
case Left(json) =>
288-
throw new IllegalArgumentException(
289-
s"Status code and message expected but got a json value '${json}'."
290-
)
291-
}
292-
293281
/**
294282
* This operation creates a Pinecone index. You can use it to specify the measure of
295283
* similarity, the dimension of vectors to be stored in the index, the numbers of replicas to
@@ -318,27 +306,27 @@ abstract class PineconeIndexServiceImpl[S <: IndexSettings](
318306
): Nothing =
319307
throw new PineconeScalaClientException(s"Code ${httpCode} : ${message}")
320308

321-
protected def handleCreateResponse(response: RichJsResponse): CreateResponse = {
322-
val (statusCode, message) = statusCodeAndMessage(response)
323-
324-
statusCode match {
309+
protected def handleCreateResponse(response: RichResponse): CreateResponse =
310+
response.status.code match {
325311
case 201 => CreateResponse.Created
326312
// Encountered when request exceeds quota or an invalid index name.
327313
case 400 => CreateResponse.BadRequest
328314
case 409 => CreateResponse.AlreadyExists
329-
case _ => throw new PineconeScalaClientException(s"Code ${statusCode} : ${message}")
315+
case _ =>
316+
throw new PineconeScalaClientException(
317+
s"Code ${response.status.code} : ${response.status.message}"
318+
)
330319
}
331-
}
332320

333-
protected def handleDeleteResponse(response: RichJsResponse): DeleteResponse = {
334-
val (statusCode, message) = statusCodeAndMessage(response)
335-
336-
statusCode match {
321+
protected def handleDeleteResponse(response: RichResponse): DeleteResponse =
322+
response.status.code match {
337323
case 202 => DeleteResponse.Deleted
338324
case 404 => DeleteResponse.NotFound
339-
case _ => throw new PineconeScalaClientException(s"Code ${statusCode} : ${message}")
325+
case _ =>
326+
throw new PineconeScalaClientException(
327+
s"Code ${response.status.code} : ${response.status.message}"
328+
)
340329
}
341-
}
342330
}
343331

344332
object PineconeIndexServiceFactory extends PineconeServiceFactoryHelper {

0 commit comments

Comments
 (0)