Find answers from the community

J
Joey
Offline, last seen 3 months ago
Joined September 25, 2024
Exception ignored in: <function QdrantClient.del at 0x135be9580>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/qdrant_client/qdrant_client.py", line 129, in del
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/qdrant_client/qdrant_client.py", line 136, in close
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/qdrant_client/local/qdrant_local.py", line 59, in close
TypeError: 'NoneType' object is not callable



for below code:

for doc in docs:
if "content_text" in doc:
doc_content = doc["content_text"]
doc_id = doc["document_id"]
print(doc_id)
documents.append(
Document(
text=doc_content,
metadata={"file_name": docid,"date": str(datetime.now())}, id=doc_id,
description=f"Useful to answer question related to file name or id {doc_id}",
)
)
client = QdrantClient(path="./qdrant_data")
vector_store = QdrantVectorStore(
"chatbot", client=client, enable_hybrid=True, batch_size=20
)

storage_context = StorageContext.from_defaults(vector_store=vector_store)
service_context = ServiceContext.from_defaults(
chunk_size=512
)
index = VectorStoreIndex.from_documents(documents,
storage_context=storage_context,
service_context=service_context,
show_progress=True)
index.storage_context.persist(persist_dir="./storage")

index = load_index_from_storage(
StorageContext.from_defaults(persist_dir="./storage")
)
7 comments
L
W
def api_get_chatbot_response(self, project_id, question, index):
answer = ""
try:
persist_dir = self.config.host.path + f"projects/{project_id}/docs/reports/llama_vectordb"
# Set your OpenAI API key
openai.api_key = ""
index = load_index_from_storage(
StorageContext.from_defaults(persist_dir=persist_dir)
)

qa_prompt = PromptTemplate(
)


class RAGStringQueryEngine(CustomQueryEngine):
"""RAG String Query Engine."""

retriever: BaseRetriever
response_synthesizer: BaseSynthesizer
llm: OpenAI
qa_prompt: PromptTemplate

def custom_query(self, query_str: str):
nodes = self.retriever.retrieve(query_str)

context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = self.llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)

return str(response)

# configure retriever
retriever = VectorIndexRetriever(
index=index,
similarity_top_k=2,
)

# configure response synthesizer
response_synthesizer = get_response_synthesizer(
streaming=True,
response_mode="tree_summarize",
)
llm = OpenAI(model="gpt-3.5-turbo")

# assemble query engine
query_engine = RAGStringQueryEngine(
retriever=retriever,
response_synthesizer=response_synthesizer,
llm=llm,
qa_prompt=qa_prompt,
)

answer = str(query_engine.query(question))



here I want to load the index separetly and keep it loaded , I will call this api to get the answer everytime
1 comment
L
How do i make async call using RAGStringQueryEngine?
3 comments
r
k
class RAGStringQueryEngine(CustomQueryEngine):
"""RAG String Query Engine."""

retriever: BaseRetriever
response_synthesizer: BaseSynthesizer
llm: OpenAI
qa_prompt: PromptTemplate

async def acustom_query(self, query_str: str):
nodes = await self.retriever.retrieve(query_str)

context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = await self.llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)

return str(response)
How do i as a question using aquery here?
2 comments
k
how should I async query>
5 comments
k
J
How do Load only necessary data based on the query?
3 comments
k
index = load_index_from_storage(
StorageContext.from_defaults(persist_dir="./storage")
)

what is the type of variable index here?
20 comments
k
J
def api_get_chatbot_response(self, project_id, question, index):
answer = ""
try:
persist_dir = self.config.host.path + f"projects/{project_id}/docs/reports/llama_vectordb"
# Set your OpenAI API key
openai.api_key = ""
index = load_index_from_storage(
StorageContext.from_defaults(persist_dir=persist_dir)
)

qa_prompt = PromptTemplate(
)


class RAGStringQueryEngine(CustomQueryEngine):
"""RAG String Query Engine."""

retriever: BaseRetriever
response_synthesizer: BaseSynthesizer
llm: OpenAI
qa_prompt: PromptTemplate

def custom_query(self, query_str: str):
nodes = self.retriever.retrieve(query_str)

context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = self.llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)

return str(response)

# configure retriever
retriever = VectorIndexRetriever(
index=index,
similarity_top_k=2,
)

# configure response synthesizer
response_synthesizer = get_response_synthesizer(
streaming=True,
response_mode="tree_summarize",
)
llm = OpenAI(model="gpt-3.5-turbo")

# assemble query engine
query_engine = RAGStringQueryEngine(
retriever=retriever,
response_synthesizer=response_synthesizer,
llm=llm,
qa_prompt=qa_prompt,
)

answer = str(query_engine.query(question))

I want to load the index separetly and keep it loaded , I will call this api to get the answer everytime
2 comments
k
How do i pass the loaded index from api to another
4 comments
J
k
qa_prompt = PromptTemplate(
"Context information is below.\n"
"---------------------\n"
"{context_str}\n"
"---------------------\n"
"Given the context information and not prior knowledge, "
"answer the query.\n"
"Query: {query_str}\n"
"Answer: "
)


class RAGStringQueryEngine(CustomQueryEngine):
"""RAG String Query Engine."""

retriever: BaseRetriever
response_synthesizer: BaseSynthesizer
llm: OpenAI
qa_prompt: PromptTemplate

def custom_query(self, query_str: str):
nodes = self.retriever.retrieve(query_str)

context_str = "\n\n".join([n.node.get_content() for n in nodes])
response = self.llm.complete(
qa_prompt.format(context_str=context_str, query_str=query_str)
)

return str(response)


configure retriever

retriever = VectorIndexRetriever(
index=index,
similarity_top_k=2,
)

configure response synthesizer

response_synthesizer = get_response_synthesizer(
streaming=True,
response_mode="tree_summarize",
)
llm = OpenAI(model="gpt-3.5-turbo")

assemble query engine

query_engine = RAGStringQueryEngine(
retriever=retriever,
response_synthesizer=response_synthesizer,
llm=llm,
qa_prompt=qa_prompt,
)

query

start_time = time.perf_counter()
streaming_response = query_engine.query('''''')
elapsed_time = time.perf_counter() - start_time

print(f"{elapsed_time:0.3f}s")

Or iterate over the tokens as they arrive

for text in streaming_response.response_gen:
print(text, end="")

I am unable to stream response here
3 comments
L
How do I add system prompts for my chatbot
22 comments
W
J
O
How do i use loaded index out of its scope in another api?
3 comments
k
@kapa.ai How Do I query index using splade?
2 comments
k
@kapa.ai what is collection_name in Qdrant ?
12 comments
k
J
J
Joey
·

Splade

@kapa.ai How do i add splade into llamaIndex
4 comments
W
J
Can I add document id while creating a documents and query based on the document id?
3 comments
O
L