How to save the indexes being created in
get_query_engine()
to pinecone? Like in
index.storage_context.persist("./test_indexcache_one/")
, they are being saved locally.
def get_query_engine(llm, filename):
# use Huggingface embeddings
embed_model = HuggingFaceEmbeddings(
model_name="sentence-transformers/all-mpnet-base-v2"
)
# create a service context
service_context = ServiceContext.from_defaults(
llm=llm,
embed_model=embed_model,
)
# set_global_service_context(service_context)
# # load documents
documents = SimpleDirectoryReader(
input_files = [f"./docs/{filename}"]
).load_data()
# documents = SimpleDirectoryReader("./test_docs").load_data()
# # create vector store index
index = VectorStoreIndex.from_documents(documents, service_context=service_context)
index.storage_context.persist("./test_indexcache_one/")
# set up query engine
query_engine = index.as_query_engine(
streaming=True,
similarity_top_k=1
)
return query_engine