Skip to main content
Build an AI agent that uses Pinecone to retrieve knowledge and answer questions accurately. This demo shows Pinecone as a tool inside an agent, which is the same pattern you’d use in production.
This guide requires an Anthropic or OpenAI API key alongside your Pinecone API key.
1

Install dependencies

2

Create an index and load knowledge

Create a Pinecone index with integrated embedding and load a small knowledge base. These are facts your LLM doesn’t know on its own, so retrieval is the only way to answer accurately.
Pinecone is eventually consistent. New records may take a few seconds to become searchable.
3

Define Pinecone as a tool

Wrap Pinecone search in a function your agent can call. Drop this into any agent codebase to add knowledge retrieval. Run all snippets in the same Python session so index and llm stay in scope.
Agent tool: search_knowledge_base
Python
4

Wire the tool into your agent

Give your LLM the ability to call the search function when it needs information.
5

Ask your agent a question

If the agent says it can’t find the information, wait a few seconds and retry. Pinecone is eventually consistent, so freshly upserted records take a moment to become searchable.Your agent searches Pinecone, retrieves the relevant policy, and answers:
Output
Try a few more questions:
What just happened: Your LLM received a question, decided it needed more information, and called the search_knowledge_base tool. Pinecone returned the most relevant records with reranking, and the LLM synthesized an accurate answer from the retrieved context. Production RAG agents use this same pattern, and the search_knowledge_base function works in any agent framework.

Next steps

Use the MCP server

Give agents Pinecone access over the Model Context Protocol

Search methods

Explore semantic, hybrid, and full-text search

Data modeling

Model your data for efficient retrieval