Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 5229dfb

Browse files
committed
New examples (ListVectorIds, QueryVectorsByFilter, DescribeIndex) + Version 0.1.2
1 parent 1caf305 commit 5229dfb

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ organization := "io.cequence"
22

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

5-
version := "0.1.0"
5+
version := "0.1.2"
66

77
// Supported Scala versions
88
val scala212 = "2.12.15"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.cequence.pineconescala.demo
2+
3+
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV must be set
4+
object DescribeIndex extends PineconeDemoApp {
5+
override protected def exec =
6+
pineconeIndexService.describeIndex("auto-gpt-test").map(
7+
_.foreach(println)
8+
)
9+
}

src/main/scala/io/cequence/pineconescala/demo/ListIndexes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.cequence.pineconescala.demo
22

3-
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV must be set
3+
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV (optional) must be set
44
object ListIndexes extends PineconeDemoApp {
55
override protected def exec =
66
pineconeIndexService.listIndexes.map(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.cequence.pineconescala.demo
2+
3+
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV must be set
4+
object ListVectorIds extends PineconeDemoApp {
5+
override protected def exec =
6+
createPineconeVectorService("auto-gpt-test").flatMap(
7+
_.listVectorIDs(
8+
namespace = "wild-test",
9+
limit = Some(10),
10+
)
11+
).map { queryResponse =>
12+
val ids = queryResponse.vectors.map(_.id).mkString(", ")
13+
println(s"Vector Ids: ${ids}")
14+
println(s"Pagination: ${queryResponse.pagination}")
15+
println(s"Namespace : ${queryResponse.namespace}")
16+
}
17+
}

src/main/scala/io/cequence/pineconescala/demo/QueryVectors.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package io.cequence.pineconescala.demo
22

3+
import io.cequence.pineconescala.domain.settings.QuerySettings
4+
35
import scala.util.Random
46

57
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV must be set
68
object QueryVectors extends PineconeDemoApp {
79

10+
private val indexName = "auto-gpt-test"
11+
private val namespace = "my_namespace"
12+
813
override protected def exec =
9-
createPineconeVectorService("auto-gpt-test").flatMap(
14+
createPineconeVectorService(indexName).flatMap(
1015
_.query(
1116
vector = Seq.fill(1536)(Random.nextDouble), // some values/embeddings
12-
namespace = "my_namespace"
17+
namespace
1318
)
1419
).map { queryResponse =>
1520
queryResponse.matches.foreach { matchInfo =>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.cequence.pineconescala.demo
2+
3+
import io.cequence.pineconescala.domain.settings.QuerySettings
4+
5+
import scala.util.Random
6+
7+
// run me - env. variables PINECONE_SCALA_CLIENT_API_KEY and PINECONE_SCALA_CLIENT_ENV must be set
8+
object QueryVectorsByFilter extends PineconeDemoApp {
9+
10+
private val indexName = "auto-gpt-test"
11+
private val namespace = "my_namespace"
12+
13+
override protected def exec =
14+
createPineconeVectorService(indexName).flatMap(
15+
_.query(
16+
vector = Seq.fill(1536)(Random.nextDouble), // some values/embeddings
17+
namespace,
18+
settings = QuerySettings(
19+
topK = 10,
20+
includeValues = false,
21+
includeMetadata = true,
22+
filter = Map(
23+
"subjectId" -> Seq("1234", "5678")
24+
)
25+
)
26+
)
27+
).map { queryResponse =>
28+
println("Matches #: " + queryResponse.matches.size)
29+
queryResponse.matches.foreach { matchInfo =>
30+
println(s"Matched vector id: ${matchInfo.id}")
31+
println(s"Matched vector values: ${matchInfo.values.take(20).mkString(", ")}..") // by default values are not included
32+
println(s"Matched vector score: ${matchInfo.score}")
33+
println(s"Matched vector metadata: ${matchInfo.metadataUnwrapped.filter(_._1 != "text")}") // by default metadata is included
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)