import pymongo
import openai
import os
from llama_index import VectorStoreIndex, StorageContext, SimpleDirectoryReader
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
from llama_index.storage.storage_context import StorageContext
openai.api_key = os.getenv("OPENAI_API_KEY")
# setup mongo connection
mongo_uri = os.environ(mongo_uri)
# setup client
mongodb_client = pymongo.MongoClient(mongo_uri)
if mongodb_client :
print("Connection is successful!")
else:
print("Connection is not successful!")
# setup store
store = MongoDBAtlasVectorSearch(mongodb_client)
# print(store)
# setup storage context
storage_context = StorageContext.from_defaults(
vector_store= store
)
documents = SimpleDirectoryReader("input/text").load_data()
index = VectorStoreIndex.from_documents(documents, storage_context= storage_context)
print(index)
# ask query
query_engine = index.as_query_engine()
response = query_engine.query("What did author work on after college?")
print(response)
#initialize pinecone client
pinecone.init(api_key=api_key, environment="us-west1-gcp-free")
pinecone_index = pinecone.Index("pi-starter-index")
#load document
documents = SimpleDirectoryReader('input/text').load_data()
# create vector store
vector_store = PineconeVectorStore(
pinecone_index=pinecone_index
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
Traceback (most recent call last):
File "c:\MyStuffs\Code\llama_index\vector db\basic_pinecone_db.py", line 30, in <module>
vector_store = PineconeVectorStore(
File "C:\Python39\lib\site-packages\llama_index\vector_stores\pinecone.py", line 169, in __init__
tokenizer = get_default_tokenizer()
File "C:\Python39\lib\site-packages\llama_index\vector_stores\pinecone.py", line 82, in get_default_tokenizer
** from transformers import BertTokenizerFast
ModuleNotFoundError: No module named 'transformers' **