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

What is Pinecone?

Pinecone is a popular cloud-based vector database, which allows you to store and search vectors efficiently.


  1. Pinecone Account: Before you start, sign up for a Pinecone account.

  2. Pinecone Project: Once registered, create a new project, an index, and generate an API key. You’ll need these details for configuration.

  3. OpenAI Account: Create an account at OpenAI Signup and generate the token at API Keys.


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

  • Pinecone API Key

  • Pinecone Environment

  • Pinecone Project ID

  • Pinecone Index Name

  • Pinecone Namespace

This information is available to you in the Pinecone UI portal.

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.

Additionally, you’ll need to provide your OpenAI API Key. Set it as an environment variable like so:



To acquire Spring AI artifacts, declare the Spring Snapshot repository:

	<name>Spring Snapshots</name>


Add these dependencies to your project:

  • OpenAI: Required for calculating embeddings.

  • Pinecone

Refer to the Dependency Management section to add the Spring AI BOM to your build file.

Sample Code

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

public PineconeVectorStoreConfig pineconeVectorStoreConfig() {

    return PineconeVectorStoreConfig.builder()
        .withNamespace("") // the free tier doesn't support namespaces.

Integrate with OpenAI’s embeddings by adding the Spring Boot OpenAI starter to your project. This provides you with an implementation of the Embeddings client:

public VectorStore vectorStore(PineconeVectorStoreConfig config, EmbeddingClient embeddingClient) {
    return new PineconeVectorStore(config, embeddingClient);

In your main code, create some documents:

List<Document> documents = List.of(
	new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
	new Document("The World is Big and Salvation Lurks Around the Corner"),
	new Document("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));

Add the documents to Pinecone:


And finally, retrieve documents similar to a query:

List<Document> results = vectorStore.similaritySearch(SearchRequest.query("Spring").withTopK(5));

If all goes well, you should retrieve the document containing the text "Spring AI rocks!!".