Skip to content

Commit

Permalink
fix redundant embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
seehi committed Apr 24, 2024
1 parent 263d799 commit e976ece
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/rag_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def rag_key(self) -> str:


class RAGExample:
"""Show how to use RAG."""
"""Show how to use RAG.
Default engine use LLM Reranker, if the answer from the LLM is incorrect, may encounter `IndexError: list index out of range`.
"""

def __init__(self, engine: SimpleEngine = None):
self._engine = engine
Expand All @@ -59,6 +62,7 @@ def engine(self):
def engine(self, value: SimpleEngine):
self._engine = value

@handle_exception
async def run_pipeline(self, question=QUESTION, print_title=True):
"""This example run rag pipeline, use faiss retriever and llm ranker, will print something like:
Expand All @@ -79,6 +83,7 @@ async def run_pipeline(self, question=QUESTION, print_title=True):
answer = await self.engine.aquery(question)
self._print_query_result(answer)

@handle_exception
async def add_docs(self):
"""This example show how to add docs.
Expand Down Expand Up @@ -148,6 +153,7 @@ async def add_objects(self, print_title=True):
except Exception as e:
logger.error(f"nodes is empty, llm don't answer correctly, exception: {e}")

@handle_exception
async def init_objects(self):
"""This example show how to from objs, will print something like:
Expand All @@ -160,6 +166,7 @@ async def init_objects(self):
await self.add_objects(print_title=False)
self.engine = pre_engine

@handle_exception
async def init_and_query_chromadb(self):
"""This example show how to use chromadb. how to save and load index. will print something like:
Expand Down Expand Up @@ -233,7 +240,7 @@ async def _retrieve_and_print(self, question):


async def main():
"""RAG pipeline"""
"""RAG pipeline."""
e = RAGExample()
await e.run_pipeline()
await e.add_docs()
Expand Down

0 comments on commit e976ece

Please sign in to comment.