Files
mem0/notebooks/pinecone.ipynb
T
2023-12-29 16:52:41 +05:30

3.8 KiB

Cookbook for using PineconeDB with Embedchain

Step-1: Install embedchain package

In [ ]:
!pip install embedchain[dataloaders,pinecone]

Step-2: Set environment variables needed for Pinecone

You can find this env variable on your OpenAI dashboard and Pinecone dashboard.

In [ ]:
import os
from embedchain import App

os.environ["OPENAI_API_KEY"] = "sk-xxx"
os.environ["PINECONE_API_KEY"] = "xxx"
os.environ["PINECONE_ENV"] = "xxx"

Step-3: Define your Vector Database config

In [ ]:
config = """
vectordb:
  provider: pinecone
  config:
    metric: cosine
    vector_dimension: 768
    collection_name: pc-index
"""

# Write the multi-line string to a YAML file
with open('pinecone.yaml', 'w') as file:
    file.write(config)

Step-4 Create embedchain app based on the config

In [ ]:
app = App.from_config(config_path="pinecone.yaml")

Step-5: Add data sources to your app

In [ ]:
app.add("https://www.forbes.com/profile/elon-musk")
In [ ]:
while(True):
    question = input("Enter question: ")
    if question in ['q', 'exit', 'quit']:
        break
    answer = app.query(question)
    print(answer)