Skip to content

Commit

Permalink
fix rag documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wenduren committed Nov 29, 2024
1 parent ad0e9c5 commit 5bde304
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions docs/en/Cookbook/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Now that we have two different retrieval functions returning results in differen
# Part8

reranker = Reranker(name="ModuleReranker",
model="bge-reranker-large",
model=lazyllm.OnlineEmbeddingModule(type="rerank"),
topk=1)
```

Expand Down Expand Up @@ -179,7 +179,7 @@ retriever2 = lazyllm.Retriever(doc=documents,
# Part8

reranker = lazyllm.Reranker(name='ModuleReranker',
model="bge-reranker-large",
model=lazyllm.OnlineEmbeddingModule(type="rerank"),
topk=1)

# Part3
Expand Down Expand Up @@ -251,7 +251,7 @@ with lazyllm.pipeline() as ppl:
topk=3)

ppl.reranker = lazyllm.Reranker(name='ModuleReranker',
model="bge-reranker-large",
model=lazyllm.OnlineEmbeddingModule(type="rerank"),
topk=1) | bind(query=ppl.input)

ppl.formatter = (
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/Cookbook/rag.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ retriever2 = lazyllm.Retriever(doc=documents,
# Part8

reranker = lazyllm.Reranker(name='ModuleReranker',
model="bge-reranker-large",
model=lazyllm.OnlineEmbeddingModule(type="rerank"),
topk=1)

# Part3
Expand Down Expand Up @@ -250,7 +250,7 @@ with lazyllm.pipeline() as ppl:
topk=3)

ppl.reranker = lazyllm.Reranker(name='ModuleReranker',
model="bge-reranker-large",
model=lazyllm.OnlineEmbeddingModule(type="rerank"),
topk=1) | bind(query=ppl.input)

ppl.formatter = (
Expand Down
33 changes: 17 additions & 16 deletions lazyllm/docs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@
>>> import lazyllm
>>> from lazyllm.tools import Document, Reranker, Retriever
>>> m = lazyllm.OnlineEmbeddingModule()
>>> documents = Document(dataset_path='rag_master', embed=m, manager=False)
>>> documents = Document(dataset_path='/path/to/user/data', embed=m, manager=False)
>>> retriever = Retriever(documents, group_name='CoarseChunk', similarity='bm25', similarity_cut_off=0.01, topk=6)
>>> reranker = Reranker(name='ModuleReranker', model='bg-reranker-large', topk=1)
>>> reranker = Reranker(name='ModuleReranker', model='bge-reranker-large', topk=1)
>>> ppl = lazyllm.ActionModule(retriever, reranker)
>>> ppl.start()
>>> print(ppl("query"))
>>> print(ppl("user query"))
''')

# ---------------------------------------------------------------------------- #
Expand Down Expand Up @@ -346,19 +346,19 @@
>>> import lazyllm
>>> from lazyllm.tools import Retriever, Document, SentenceSplitter
>>> m = lazyllm.OnlineEmbeddingModule()
>>> documents = Document(dataset_path='your_doc_path', embed=m, manager=False)
>>> documents = Document(dataset_path='/path/to/user/data', embed=m, manager=False)
>>> rm = Retriever(documents, group_name='CoarseChunk', similarity='bm25', similarity_cut_off=0.01, topk=6)
>>> rm.start()
>>> print(rm("query"))
>>> print(rm("user query"))
>>> m1 = lazyllm.TrainableModule('bge-large-zh-v1.5').start()
>>> document1 = Document(dataset_path='your_doc_path', embed={'online':m , 'local': m1}, manager=False)
>>> document1 = Document(dataset_path='/path/to/user/data', embed={'online':m , 'local': m1}, manager=False)
>>> document1.create_node_group(name='sentences', transform=SentenceSplitter, chunk_size=1024, chunk_overlap=100)
>>> retriever = Retriever(document1, group_name='sentences', similarity='cosine', similarity_cut_off=0.4, embed_keys=['local'], topk=3)
>>> print(retriever("query"))
>>> document2 = Document(dataset_path='your_doc_path', embed={'online':m , 'local': m1}, manager=False)
>>> print(retriever("user query"))
>>> document2 = Document(dataset_path='/path/to/user/data', embed={'online':m , 'local': m1}, manager=False)
>>> document2.create_node_group(name='sentences', transform=SentenceSplitter, chunk_size=512, chunk_overlap=50)
>>> retriever2 = Retriever([document1, document2], group_name='sentences', similarity='cosine', similarity_cut_off=0.4, embed_keys=['local'], topk=3)
>>> print(retriever2("query"))
>>> print(retriever2("user query"))
''')

# ---------------------------------------------------------------------------- #
Expand Down Expand Up @@ -430,15 +430,16 @@

add_example('LLMParser.transform', '''
>>> import lazyllm
>>> from lazyllm.tools import LLMParser, TrainableModule
>>> llm = TrainableModule("internlm2-chat-7b")
>>> m = lazyllm.TrainableModule("bge-large-zh-v1.5")
>>> from lazyllm.tools import LLMParser
>>> llm = lazyllm.TrainableModule("internlm2-chat-7b").start()
>>> m = lazyllm.TrainableModule("bge-large-zh-v1.5").start()
>>> summary_parser = LLMParser(llm, language="en", task_type="summary")
>>> keywords_parser = LLMParser(llm, language="en", task_type="keywords")
>>> documents = Document(dataset_path='your_doc_path', embed=m, manager=False)
>>> rm = Retriever(documents, group_name='CoarseChunk', similarity='bm25', similarity_cut_off=0.01, topk=6)
>>> summary_result = summary_parser.transform(rm[0])
>>> keywords_result = keywords_parser.transform(rm[0])
>>> documents = lazyllm.Document(dataset_path="/path/to/your/data", embed=m, manager=False)
>>> rm = lazyllm.Retriever(documents, group_name='CoarseChunk', similarity='bm25', topk=6)
>>> doc_nodes = rm("test")
>>> summary_result = summary_parser.transform(doc_nodes[0])
>>> keywords_result = keywords_parser.transform(doc_nodes[0])
''')

# ---------------------------------------------------------------------------- #
Expand Down

0 comments on commit 5bde304

Please sign in to comment.