Skip to main content
OpenAI’s large language models (LLMs) enhance semantic search, or “long-term memory,” for LLMs. This combination uses OpenAI’s embedding and completion (or generation) endpoints alongside Pinecone’s vector search for information retrieval. By integrating OpenAI’s LLMs with Pinecone, you can combine deep learning capabilities for embedding generation with efficient vector storage and retrieval. This approach goes beyond traditional keyword-based search and returns context-aware results.

Setup guide

This guide shows how to integrate OpenAI’s LLMs with Pinecone, a combination referred to as the OP stack. LLMs like OpenAI’s text-embedding-3-small generate vector embeddings, i.e., numerical representations of text semantics. These embeddings enable semantic matches rather than literal text matches. Additionally, LLMs like gpt-4o-mini can predict text completions based on information provided from these contexts. Pinecone Database stores and queries high-dimensional vectors and provides fast semantic search over them. There are many ways to integrate these two tools, and Pinecone has several guides that focus on specific use cases. If you already know what you’d like to do, start with one of these:

Introduction to embeddings

At the core of the OP stack are embeddings, which come from the OpenAI Embedding API. You index those embeddings in Pinecone Database for fast, scalable retrieval augmentation of your LLMs and other information retrieval use cases. This example demonstrates the core OP stack. It’s the simplest workflow and is present in each of the other workflows, but it isn’t the only way to use the stack. For more advanced usage, see the guides listed earlier. The OP stack is built for semantic search, question-answering, threat-detection, and other applications that rely on language models and a large corpus of text data. The basic workflow looks like this:
  • Embed and index
    • Use the OpenAI Embedding API to generate vector embeddings of your documents (or any text data).
    • Upload those vector embeddings into Pinecone, which can store and index millions or billions of these vector embeddings and search through them at low latency.
  • Search
    • Pass your query text or document through the OpenAI Embedding API again.
    • Take the resulting vector embedding and send it as a query to Pinecone.
    • Get back semantically similar documents, even if they don’t share any keywords with the query.
Basic workflow of OpenAI and Pinecone
1

Set up the environment

Start by installing the OpenAI and Pinecone clients, along with Hugging Face Datasets for downloading the TREC dataset used in this guide.
Shell
2

Create embeddings

To create embeddings, first initialize your connection to OpenAI. Sign up for an API key at OpenAI.
Python
You can now create embeddings with the OpenAI v3 small embedding model.
Python
In res, you should find a JSON-like object containing two 1536-dimensional embeddings. These are the vector representations of the two inputs. To access the embeddings directly, extract them to a list.
Python
You’ll use this logic later when you create embeddings for the Text REtrieval Conference (TREC) question classification dataset.
3

Create an index

Next, initialize an index to store the vector embeddings. For this, you need a Pinecone API key. Sign up for one.
Python
4

Store the embeddings

With both OpenAI and Pinecone connections initialized, you can populate the index. For this, you need the TREC dataset.
Python
Then create a vector embedding for each question using OpenAI (as demonstrated earlier), and upsert the ID, vector embedding, and original text for each phrase to Pinecone.
Python
6

Clean up

When you’re finished with the index, delete it to save resources.
Python

Resources