diff --git a/examples/data_/BartoSutton.pdf b/examples/data_/BartoSutton.pdf deleted file mode 100644 index 9deb811..0000000 Binary files a/examples/data_/BartoSutton.pdf and /dev/null differ diff --git a/examples/main_cli_example.py b/examples/main_cli_example.py index e89e1ee..a03035c 100644 --- a/examples/main_cli_example.py +++ b/examples/main_cli_example.py @@ -72,6 +72,7 @@ async def main(): chat = LeannChat(index_path=INDEX_PATH) query = "Based on the paper, what are the main techniques LEANN explores to reduce the storage overhead and DLPM explore to achieve Fairness and Efiiciency trade-off?" + query = "What is the main idea of RL and give me 5 exapmle of classic RL algorithms?" print(f"You: {query}") chat_response = chat.ask(query, top_k=20, recompute_beighbor_embeddings=True) print(f"Leann: {chat_response}") diff --git a/examples/resue_index.py b/examples/resue_index.py new file mode 100644 index 0000000..6e7dbfc --- /dev/null +++ b/examples/resue_index.py @@ -0,0 +1,18 @@ +import asyncio +from leann.api import LeannChat +from pathlib import Path + +INDEX_DIR = Path("./test_pdf_index") +INDEX_PATH = str(INDEX_DIR / "pdf_documents.leann") + +async def main(): + print(f"\n[PHASE 2] Starting Leann chat session...") + chat = LeannChat(index_path=INDEX_PATH) + query = "What is the main idea of RL and give me 5 exapmle of classic RL algorithms?" + query = "Based on the paper, what are the main techniques LEANN explores to reduce the storage overhead and DLPM explore to achieve Fairness and Efiiciency trade-off?" + + response = chat.ask(query,top_k=20,recompute_beighbor_embeddings=True,complexity=64,beam_width=1) + print(f"\n[PHASE 2] Response: {response}") + +if __name__ == "__main__": + asyncio.run(main()) \ No newline at end of file diff --git a/packages/leann-core/src/leann/api.py b/packages/leann-core/src/leann/api.py index 48478bf..014264a 100644 --- a/packages/leann-core/src/leann/api.py +++ b/packages/leann-core/src/leann/api.py @@ -217,7 +217,12 @@ class LeannChat: results = self.searcher.search(question, top_k=top_k, **kwargs) context = "\n\n".join([r.text for r in results]) - prompt = f"Context:\n{context}\n\nQuestion: {question}\n\nAnswer:" + prompt = ( + "Here is some retrieved context that might help answer your question:\n\n" + f"{context}\n\n" + f"Question: {question}\n\n" + "Please provide the best answer you can based on this context and your knowledge." + ) print(f"DEBUG: Calling LLM with prompt: {prompt}...") try: