response = llm.stream_complete(fmt_qa_prompt)
async def generate_tokens():
for r in response:
try:
yield(r.delta)
await asyncio.sleep(.05)
except asyncio.CancelledError as e:
_logger.error("Cancelled")
return StreamingResponse(generate_tokens(), media_type="text/event-stream")
query_engine = index.as_query_engine()
chain = load_qa_chain(llm, chain_type="stuff")
res = chain.run(input_documents=docs, question=prompt)
c_tool = RetrieverTool.from_defaults(
retriever=retriever_c,
description=("Usefull to retrieve any information related to c"),
)
router_retriever = RouterRetriever(
selector=LLMSingleSelector.from_defaults(service_context=service_context),
retriever_tools=[
a_tool,
b_tool,
c_tool
],
)
service_context = ServiceContext.from_defaults(
llm=llm,
embed_model=base_embeddings,
chunk_size=512
)
vector_store = FaissVectorStore.from_persist_dir('./storage')
storage_context = StorageContext.from_defaults(
vector_store=vector_store, persist_dir='./storage'
)
index = load_index_from_storage(
storage_context=storage_context,
service_context=service_context
)
query_engine = index.as_query_engine()
response = query_engine.query(query)
self._index.index_struct.nodes_dict[idx] for idx in query_result.ids
KeyError: '1'
for node in nodes:
node_embedding = base_embeddings.get_text_embedding(
node.get_content(metadata_mode="all")
)
node.embedding = node_embedding
vector_store.add(nodes)
index.storage_context.persist()
vector_store = QdrantVectorStore(index_name, client=client, enable_hybrid=True, batch_size=20)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
...
vector_store.add(nodes)
index.storage_context.persist()
node_embedding = embed_model.get_text_embedding(
node.get_content(metadata_mode="all")
)