You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This section walks you through setting up the Pinecone `VectorStore` to store document embeddings and perform similarity searches.
4
4
5
-
== What is Pinecone?
6
-
7
5
link:https://www.pinecone.io/[Pinecone] is a popular cloud-based vector database, which allows you to store and search vectors efficiently.
8
6
9
7
== Prerequisites
10
8
11
9
1. Pinecone Account: Before you start, sign up for a link:https://app.pinecone.io/[Pinecone account].
12
10
2. Pinecone Project: Once registered, create a new project, an index, and generate an API key. You'll need these details for configuration.
13
-
3. OpenAI Account: Create an account at link:https://platform.openai.com/signup[OpenAI Signup] and generate the token at link:https://platform.openai.com/account/api-keys[API Keys].
14
-
15
-
== Configuration
11
+
3. `EmbeddingClient` instance to compute the document embeddings. Several options are available:
12
+
- If required, an API key for the xref:api/embeddings.adoc#available-implementations[EmbeddingClient] to generate the embeddings stored by the `PineconeVectorStore`.
16
13
17
14
To set up `PineconeVectorStore`, gather the following details from your Pinecone account:
18
15
@@ -27,32 +24,135 @@ To set up `PineconeVectorStore`, gather the following details from your Pinecone
27
24
This information is available to you in the Pinecone UI portal.
28
25
====
29
26
30
-
When setting up embeddings, select a vector dimension of `1536`. This matches the dimensionality of OpenAI's model `text-embedding-ada-002`, which we'll be using for this guide.
27
+
== Auto-configuration
28
+
29
+
Spring AI provides Spring Boot auto-configuration for the Pinecone Vector Sore.
30
+
To enable it, add the following dependency to your project's Maven `pom.xml` file:
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
40
50
41
-
To acquire Spring AI artifacts, declare the Spring Snapshot repository:
51
+
TIP: Refer to the xref:getting-started.adoc#repositories[Repositories] section to add Milestone and/or Snapshot Repositories to your build file.
42
52
43
-
[source,xml]
53
+
Additionally, you will need a configured `EmbeddingClient` bean. Refer to the xref:api/embeddings.adoc#available-implementations[EmbeddingClient] section for more information.
54
+
55
+
Here is an example of the needed bean:
56
+
57
+
[source,java]
58
+
----
59
+
@Bean
60
+
public EmbeddingClient embeddingClient() {
61
+
// Can be any other EmbeddingClient implementation.
62
+
return new OpenAiEmbeddingClient(new OpenAiApi(System.getenv("SPRING_AI_OPENAI_API_KEY")));
63
+
}
64
+
----
65
+
66
+
To connect to Pinecone you need to provide access details for your instance.
67
+
A simple configuration can either be provided via Spring Boot's _application.properties_,
68
+
69
+
[source,properties]
44
70
----
45
-
<repository>
46
-
<id>spring-snapshots</id>
47
-
<name>Spring Snapshots</name>
48
-
<url>https://repo.spring.io/snapshot</url>
49
-
<releases>
50
-
<enabled>false</enabled>
51
-
</releases>
52
-
</repository>
71
+
spring.ai.vectorstore.pinecone.apiKey=<your api key>
spring.ai.vectorstore.pinecone.index-name=<your index name>
75
+
76
+
# API key if needed, e.g. OpenAI
77
+
spring.ai.openai.api.key=<api-key>
53
78
----
54
79
55
-
== Dependencies
80
+
Please have a look at the list of xref:#_configuration_properties[configuration parameters] for the vector store to learn about the default values and configuration options.
81
+
82
+
Now you can Auto-wire the Pinecone Vector Store in your application and use it
83
+
84
+
[source,java]
85
+
----
86
+
@Autowired VectorStore vectorStore;
87
+
88
+
// ...
89
+
90
+
List <Document> documents = List.of(
91
+
new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
92
+
new Document("The World is Big and Salvation Lurks Around the Corner"),
93
+
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));
|`spring.ai.vectorstore.pinecone.server-side-timeout`| | 20 sec.
115
+
116
+
|===
117
+
118
+
== Metadata filtering
119
+
120
+
You can leverage the generic, portable link:https://docs.spring.io/spring-ai/reference/api/vectordbs.html#_metadata_filters[metadata filters] with the Pinecone store.
121
+
122
+
For example, you can use either the text expression language:
123
+
124
+
[source,java]
125
+
----
126
+
vectorStore.similaritySearch(
127
+
SearchRequest.defaults()
128
+
.withQuery("The World")
129
+
.withTopK(TOP_K)
130
+
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
131
+
.withFilterExpression("author in ['john', 'jill'] && article_type == 'blog'"));
132
+
----
133
+
134
+
or programmatically using the `Filter.Expression` DSL:
135
+
136
+
[source,java]
137
+
----
138
+
FilterExpressionBuilder b = new FilterExpressionBuilder();
0 commit comments