Pinecone Hybrid Search
Pinecone is a vector database with broad functionality.
This notebook goes over how to use a retriever that under the hood uses Pinecone and Hybrid Search.
The logic of this retriever is taken from this documentation
To use Pinecone, you must have an API key and an Environment. Here are the installation instructions.
%pip install --upgrade --quiet pinecone-client pinecone-text pinecone-notebooks
# Connect to Pinecone and get an API key.
from pinecone_notebooks.colab import Authenticate
Authenticate()
import os
api_key = os.environ["PINECONE_API_KEY"]
from langchain_community.retrievers import (
PineconeHybridSearchRetriever,
)
API Reference:PineconeHybridSearchRetriever
We want to use OpenAIEmbeddings
so we have to get the OpenAI API Key.
import getpass
if "OPENAI_API_KEY" not in os.environ:
os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")
Setup Pineconeโ
You should only have to do this part once.
import os
from pinecone import Pinecone, ServerlessSpec
index_name = "langchain-pinecone-hybrid-search"
# initialize Pinecone client
pc = Pinecone(api_key=api_key)
# create the index
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=1536, # dimensionality of dense model
metric="dotproduct", # sparse values supported only for dotproduct
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)
WhoAmIResponse(username='load', user_label='label', projectname='load-test')
Now that the index is created, we can use it.
index = pc.Index(index_name)