// What's Next · Done · The Associate Track
Building AI Applications with Pinecone
Completed Nov 07, 2026 · 3 hrs
Covers Pinecone index setup and management, vector ingestion with metadata, fetching and querying with distance metrics and metadata filters, updates and deletes, batching, namespaces, plus semantic search and a RAG chatbot built with OpenAI.
Indexes and setup
- Pinecone client: Initializes the API client with an API key to configure the environment.
- Serverless index: Index type that scales automatically and runs as a managed cloud service, used throughout.
- Pod-based index: Index type built on pre-configured hardware pods with chosen storage, latency, and throughput.
- create_index: Creates an index with a name, dimensionality, metric, and ServerlessSpec cloud provider.
- list_indexes: Verifies an index exists by listing indexes on the client.
- delete_index: Removes an index and all of its records, so it must be used with caution.
Vector ingestion
- upsert: Inserts new vectors or updates existing ones by ID, taking tuples of id, vector, and metadata.
- Metadata: Dictionary of extra fields stored with each vector for filtering and later retrieval.
- Dimensionality check: Verifies every vector length matches the index dimension before ingesting.
- describe_index_stats: Reports vector count, index fullness, dimensionality, and namespaces.
Retrieving vectors
- fetch: Returns records by ID, normally to explore or verify particular records.
- query: Sends a vector and returns the top_k most similar vectors with a similarity score.
- Read units (RUs): Pinecone measure of resources consumed by fetching, querying, and listing.
- Distance metric: Cosine, euclidean, or dotproduct similarity function set at index creation and not changeable later.
- Metadata filtering: Narrows the searched records with filter operators before the LLM step.
Maintaining vectors
- update: Changes vector values, metadata, or both for a given record id.
- delete: Removes vectors by ID list, by metadata filter, or all records in a namespace.
- Sequential batching: Splits upserts into chunks sent one by one, avoiding rate and size limits.
- Parallel batching: Sends many chunks at once using pool_threads and async_req for large speed gains.
Namespaces and multitenancy
- Namespace: Container that partitions an index so queries and other operations are limited to that unit.
- Multitenancy: Architecture where one index serves multiple tenant datasets in isolated namespaces.
- Implicit namespace creation: Upserting with a namespace argument creates the namespace if it does not exist.
AI applications
- Semantic search: Embeds documents and a user query, then queries the index for the most similar results.
- RAG: Retrieval-augmented generation that embeds the query, retrieves documents, and adds them to the model prompt.
- retrieve: Function that embeds the query, queries the namespace, and returns documents with sources.
- prompt_with_context_builder: Glues an instruction, retrieved documents, and the user query into one prompt.
- question_answering: Sends the contextual prompt to OpenAI's ChatCompletions endpoint and returns the answer with sources.
// Module notes
Indexes and setup
The index is the foundation every later step depends on. Pinecone is a fully managed vector database: it stores embeddings and serves queries over their semantic meaning.
- Indexes hold records, each a vector plus metadata.
- Pod-based indexes use pre-configured hardware pods; serverless indexes scale automatically on a cloud provider and often cost less.
- The client is initialized with an API key; create_index() sets name, dimension, metric, and ServerlessSpec cloud and region.
- list_indexes() verifies creation; delete_index() removes the index and every record it contains, so use it with caution.
Vector ingestion
Vectors enter the index through upsert(), which combines update and insert: an existing ID is overwritten, a new ID added. The payload is a list of id, vector, and metadata tuples.
- Check dimensionality with a list comprehension and all() so every vector length matches the index dimension.
- Metadata is a dictionary of fields such as date, category, or user attribution, stored under the metadata key for later filtering.
- describe_index_stats() confirms the upsert, though statistics can take a few moments to refresh.
Fetching, querying, and filtering
Two methods read vectors: fetch() returns records by ID, while query() sends a vector and returns the top_k most similar records with a similarity score.
- Read units measure resources consumed by fetching, querying, and listing; one RU covers a batch of 10 records.
- The distance metric, cosine by default, plus euclidean and dotproduct, is set in create_index() and cannot be changed later.
- Metadata filtering passes filter={} to query() with operators to narrow the search space and cut query latency.
Updates, deletes, batching, and namespaces
Data stays current through update() and delete(). update() changes vector values, metadata with set_metadata, or both; delete() removes vectors by ID, by metadata filter, or a namespace with delete_all.
- Upsert rate and size are limited, so large ingests are split into chunks by a generator using iter() and itertools.islice().
- Sequential batching sends chunks one by one and is slow; parallel batching uses pool_threads and async_req=True.
- Namespaces partition an index into smaller units, are created implicitly on upsert, and all index operations can target one.
Semantic search and RAG
Semantic search embeds documents and the user query with the same model, then queries the index for the closest matches. RAG adds those documents to the model prompt so the answer has extra context.
- Documents are batched, embedded through the OpenAI API, and upserted with uuid4() IDs and metadata into a namespace.
- retrieve() embeds the query, queries the namespace, and returns document texts with sources.
- prompt_with_context_builder() joins an instruction, documents, and query; question_answering() sends it to ChatCompletions and returns the answer with sources.
In plain terms
Think of Pinecone as a library that sorts books by what they mean rather than by their titles. You turn each document and each question into a vector, file it in an index with upsert, and ask for the closest matches with fetch or query, using metadata to skip whole shelves. RAG is the librarian who pulls the top few books and hands them to the model so it answers from your own material.
Worth sitting with
- Why is the distance metric locked at index creation, and what does that force you to settle before you have real query data?
- How does query cost in read units change as records grow in dimensionality and metadata, and what would you trim first?
- If documents and the user query were embedded with different models, what would break even when the index dimensionality happens to match?
// Where this fits
The concepts above are the ones this module turns on, and the notes below explain each in turn. The course page carries the whole track, and the certificate page carries the plan it belongs to.