Pinecone Database quickstart
This guide shows you how to set up and use Pinecone Database for high-performance semantic search.
To get started in your browser, use the Quickstart colab notebook. To try Pinecone Database locally before creating an account, use Pinecone Local.
1. Install an SDK
Pinecone provides SDKs in multiple languages. For this quickstart, install the Python SDK or Node.js SDK:
2. Get an API key
You need an API key to make calls to your Pinecone project.
Create a new API key in the Pinecone console, or use the widget below to generate a key. If you don’t have a Pinecone account, the widget will sign you up for the free Starter plan.
Your generated API key:
3. Create an index
In Pinecone, there are two types of indexes for storing vector data: Dense indexes store for semantic search, and sparse indexes store for lexical/keyword search.
For this quickstart, create a dense index that is integrated with an embedding model hosted by Pinecone. With integrated models, you upsert and search with text and have Pinecone generate vectors automatically.
If you prefer to use external embedding models, see Bring your own vectors.
4. Upsert text
Prepare a sample dataset of factual statements from different domains like history, physics, technology, and music. Format the data as records with an ID, text, and category.
Upsert the sample dataset into a new namespace in your index.
Because your index is integrated with an embedding model, you provide the textual statements and Pinecone converts them to dense vectors automatically.
To load large amounts of data, import from object storage or upsert in large batches.
Pinecone is eventually consistent, so there can be a slight delay before new or changed records are visible to queries. You can view index stats to check if the current vector count matches the number of vectors you upserted (50):
The response looks like this:
5. Semantic search
Search the dense index for ten records that are most semantically similar to the query, “Famous historical structures and monuments”.
Again, because your index is integrated with an embedding model, you provide the query as text and Pinecone converts the text to a dense vector automatically.
Notice that most of the results are about historical structures and monuments. However, a few unrelated statements are included as well and are ranked high in the list, for example, statements about Shakespeare and renewable energy.
To get a more accurate ranking, search again but this time rerank the initial results based on their relevance to the query.
Notice that all of the most relevant results about historical structures and monuments are now ranked highest.
6. Improve results
Reranking results is one of the most effective ways to improve search accuracy and relevance, but there are many other techniques to consider. For example:
-
Filtering by metadata: When records contain additional metadata, you can limit the search to records matching a filter expression.
-
Hybrid search: You can add lexical search to capture precise keyword matches (e.g., product SKUs, email addresses, domain-specific terms) in addition to semantic matches.
-
Chunking strategies: You can chunk your content in different ways to get better results. Consider factors like the length of the content, the complexity of queries, and how results will be used in your application.
7. Clean up
When you no longer need your example index, delete it as follows:
For production indexes, consider enabling deletion protection.
Next steps
-
Learn more about key features to keep in mind as you start building with Pinecone.
-
Check out notebooks and sample apps for different use cases.
Was this page helpful?