Find answers from the community

k
kkumar
Offline, last seen 3 months ago
Joined September 25, 2024
Hi ,
using llamaindex i am trying to read an pdf and after chunking and embedding trying to lead the document into azurecosmos db , But i am getting following error --pymongo.errors.OperationFailure: cosmosSearchOptions, full error: {'ok': 0.0, 'errmsg': 'cosmosSearchOptions', 'code': 197, 'codeName': 'InvalidIndexSpecificationOption'} my code is as below
import openai
from llama_index.llms.openai import OpenAI
from llama_index.core import Settings
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, get_response_synthesizer
from llama_index.core import StorageContext, ServiceContext, load_index_from_storage
from llama_index.embeddings.openai import OpenAIEmbedding
import pymongo
from llama_index.vector_stores.azurecosmosmongo import (
AzureCosmosDBMongoDBVectorSearch,
)
import json
import certifi
mounted_fldr = "Users/vivek/Documents/pycharmprojects/docs_process_llamaindex"
config_file = f"/{mounted_fldr}/config/config1.json"
src_data = f"/{mounted_fldr}/src_data"

index_dir = f"/{mounted_fldr}/index_data"

Set up your OpenAI API key

with open(config_file) as f:
config = json.load(f)

open_ai Access API keys

key = config['openai_api']['api_key']
openai.api_key = key
Settings.llm = OpenAI(temperature=0, model="gpt-4-turbo")
Settings.embed_model = OpenAIEmbedding(model='text-embedding-ada-002')
documents = SimpleDirectoryReader(src_data).load_data()
connection_string = f'mongodb://{u_name}:{passwd}@{host}:10255/?ssl=true'
mongodb_client = pymongo.MongoClient(connection_string,tlsCAFile=certifi.where())
print(mongodb_client.HOST)
store = AzureCosmosDBMongoDBVectorSearch(
mongodb_client=mongodb_client,
db_name="db_llama",
collection_name="test_db_pdf",
index_name="test_index"
)
storage_context = StorageContext.from_defaults(vector_store=store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context,
)
13 comments
k
W