def _initialize_index(self):
self.ctx = ServiceContext.from_defaults(llm=llm, embed_model="local")
if not os.path.exists(self.persist_dir):
documents = SimpleDirectoryReader("data").load_data()
LLAMA_13B_V2_CHAT = "a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5"
llm = Replicate(
model=LLAMA_13B_V2_CHAT,
temperature=0.01,
context_window=4096,
completion_to_prompt=self.custom_completion_to_prompt,
messages_to_prompt=messages_to_prompt,
)
self.index = VectorStoreIndex.from_documents(documents, service_context=self.ctx)
self.index.storage_context.persist(persist_dir=self.persist_dir)
else:
storage_context = StorageContext.from_defaults(persist_dir=self.persist_dir)
self.index = load_index_from_storage(storage_context, service_context=self.ctx)