Skip to content

Commit b8ca0bb

Browse files
committed
doc: Improve Pinecone layout
1 parent 6c07c4c commit b8ca0bb

File tree

2 files changed

+123
-23
lines changed

2 files changed

+123
-23
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/milvus.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ vectorStore.similaritySearch(SearchRequest.defaults()
149149
b.eq("article_type", "blog")).build()));
150150
----
151151

152-
NOTE: These filter expressions are converted into the equivalent PgVector filters.
152+
NOTE: These filter expressions are converted into the equivalent Milvus filters.
153153

154154
[[milvus-properties]]
155155
== Milvus VectorStore properties

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/pinecone.adoc

Lines changed: 122 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
This section walks you through setting up the Pinecone `VectorStore` to store document embeddings and perform similarity searches.
44

5-
== What is Pinecone?
6-
75
link:https://www.pinecone.io/[Pinecone] is a popular cloud-based vector database, which allows you to store and search vectors efficiently.
86

97
== Prerequisites
108

119
1. Pinecone Account: Before you start, sign up for a link:https://app.pinecone.io/[Pinecone account].
1210
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`.
1613

1714
To set up `PineconeVectorStore`, gather the following details from your Pinecone account:
1815

@@ -27,32 +24,135 @@ To set up `PineconeVectorStore`, gather the following details from your Pinecone
2724
This information is available to you in the Pinecone UI portal.
2825
====
2926

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:
31+
32+
[source, xml]
33+
----
34+
<dependency>
35+
<groupId>org.springframework.ai</groupId>
36+
<artifactId>spring-ai-pinecone-store-spring-boot-starter</artifactId>
37+
</dependency>
38+
----
3139

32-
Additionally, you'll need to provide your OpenAI API Key. Set it as an environment variable like so:
40+
or to your Gradle `build.gradle` build file.
3341

34-
[source,bash]
42+
[source,groovy]
3543
----
36-
export SPRING_AI_OPENAI_API_KEY='Your_OpenAI_API_Key'
44+
dependencies {
45+
implementation 'org.springframework.ai:spring-ai-pinecone-store-spring-boot-starter'
46+
}
3747
----
3848

39-
== Repository
49+
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
4050

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.
4252

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]
4470
----
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>
72+
spring.ai.vectorstore.pinecone.environment=<your environment>
73+
spring.ai.vectorstore.pinecone.projectId=<your project id>
74+
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>
5378
----
5479

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")));
94+
95+
// Add the documents
96+
vectorStore.add(List.of(document));
97+
98+
// Retrieve documents similar to a query
99+
List<Document> results = vectorStore.similaritySearch(SearchRequest.query("Spring").withTopK(5));
100+
----
101+
102+
=== Configuration properties
103+
104+
You can use the following properties in your Spring Boot configuration to customize the Pinecone vector store.
105+
106+
|===
107+
|Property| Description | Default value
108+
109+
|`spring.ai.vectorstore.pinecone.api-key`| Pinecone API Key | -
110+
|`spring.ai.vectorstore.pinecone.environment`| Pinecone environment | `gcp-starter`
111+
|`spring.ai.vectorstore.pinecone.project-id`| Pinecone project ID | -
112+
|`spring.ai.vectorstore.pinecone.index-name`| Pinecone index name | -
113+
|`spring.ai.vectorstore.pinecone.namespace`| Pinecone namespace | -
114+
|`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();
139+
140+
vectorStore.similaritySearch(SearchRequest.defaults()
141+
.withQuery("The World")
142+
.withTopK(TOP_K)
143+
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
144+
.withFilterExpression(b.and(
145+
b.in("author","john", "jill"),
146+
b.eq("article_type", "blog")).build()));
147+
----
148+
149+
NOTE: These filter expressions are converted into the equivalent Pinecone filters.
150+
151+
152+
== Manual Configuration
153+
154+
If you prefer to configure the `PineconeVectorStore` manually, you can do so by creating a `PineconeVectorStoreConfig` bean
155+
and passing it to the `PineconeVectorStore` constructor.
56156

57157
Add these dependencies to your project:
58158

@@ -78,7 +178,7 @@ Add these dependencies to your project:
78178

79179
TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
80180

81-
== Sample Code
181+
=== Sample Code
82182

83183
To configure Pinecone in your application, you can use the following setup:
84184

0 commit comments

Comments
 (0)