Recursive Retrieval рдХреНрдпрд╛ рд╣реИ?
рджрд╕реНрддрд╛рд╡реЗрдЬрд╝реЛрдВ рдХреЗ рдХрдЪреНрдЪреЗ рдЯреБрдХрдбрд╝реЛрдВ рдХреЛ рдПрдореНрдмреЗрдб рдХрд░ рдХреЗрд╡рд▓ рд╕рдорд╛рдирддрд╛ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдЙрдиреНрд╣реЗрдВ рдкреБрдирд░реНрдкреНрд░рд╛рдкреНрдд рдХрд░рдиреЗ рдХреЗ рдмрдЬрд╛рдп, recursive retrieval рдкрд╣рд▓реЗ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝реЛрдВ рдХреЗ рд╕рд╛рд░рд╛рдВрд╢реЛрдВ рдХреЛ рдПрдореНрдмреЗрдб рдХрд░рддрд╛ рд╣реИ рдФрд░ рдЙрдиреНрд╣реЗрдВ рдкреВрд░реНрдг рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдЯреБрдХрдбрд╝реЛрдВ рд╕реЗ рдЬреЛрдбрд╝рддрд╛ рд╣реИред рдЬрдм рдХреЛрдИ рдХреНрд╡реЗрд░реА рдЖрддреА рд╣реИ, рддреЛ рд╕рд┐рд╕реНрдЯрдо рдкрд╣рд▓реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рд╕рд╛рд░рд╛рдВрд╢ рдирд┐рдХрд╛рд▓рддрд╛ рд╣реИ рдФрд░ рдлрд┐рд░ рдЙрд╕рд╕реЗ рд╕рдВрдмрдВрдзрд┐рдд рдЬрд╛рдирдХрд╛рд░реА рдХреЗ рдЯреБрдХрдбрд╝реЛрдВ рддрдХ рдкрд╣реБрдБрдЪрддрд╛ рд╣реИред
рдпрд╣ рддрд░реАрдХрд╛ рдЕрдВрддрд┐рдо рдЯреБрдХрдбрд╝реЗ рджреЗрдиреЗ рд╕реЗ рдкрд╣рд▓реЗ рд░рд┐рдЯреНрд░реАрд╡рд▓ рд╕рд┐рд╕реНрдЯрдо рдХреЛ рдЕрдзрд┐рдХ рд╕рдВрджрд░реНрдн рджреЗрддрд╛ рд╣реИ, рдЬрд┐рд╕рд╕реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рдЬрд╛рдирдХрд╛рд░реА рдвреВрдБрдврдиреЗ рдХреА рдХреНрд╖рдорддрд╛ рдмреЗрд╣рддрд░ рд╣реЛрддреА рд╣реИред
LlamaIndex рдХреЗ рд╕рд╛рде Recursive Retrieval рдХрд╛ рдЗрдореНрдкреНрд▓реАрдореЗрдВрдЯреЗрд╢рди
рдЗрд╕ рдЕрдиреБрднрд╛рдЧ рдореЗрдВ, рд╣рдо LlamaIndex рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ recursive retrieval рд▓рд╛рдЧреВ рдХрд░рдиреЗ рдХреА рдЪрд░рдг-рджрд░-рдЪрд░рдг рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдмрддрд╛рдПрдБрдЧреЗ тАФ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рд▓реЛрдб рдХрд░рдиреЗ рд╕реЗ рд▓реЗрдХрд░ recursive retrieval рдХреЗ рд╕рд╛рде рдХреНрд╡реЗрд░реА рдЪрд▓рд╛рдиреЗ рддрдХред
рдЪрд░рдг 1: рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рд▓реЛрдб рдХрд░реЗрдВ рдФрд░ рддреИрдпрд╛рд░ рдХрд░реЗрдВ
рдкрд╣рд▓реЗ, рд╣рдо SimpleDirectoryReader рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рд╕рд┐рд╕реНрдЯрдо рдореЗрдВ рд▓реЛрдб рдХрд░рддреЗ рд╣реИрдВред рд╣рд░ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЛ рдПрдХ рд╢реАрд░реНрд╖рдХ рдФрд░ рдореЗрдЯрд╛рдбреЗрдЯрд╛ (рдЬреИрд╕реЗ рдЙрд╕рдХреА рд╢реНрд░реЗрдгреА) рджрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рддрд╛рдХрд┐ рдмрд╛рдж рдореЗрдВ рдлрд╝рд┐рд▓реНрдЯрд░ рдХрд░рдирд╛ рдЖрд╕рд╛рди рд╣реЛред рд▓реЛрдб рдХрд┐рдП рдЧрдП рджрд╕реНрддрд╛рд╡реЗрдЬрд╝реЛрдВ рдХреЛ рдЖрд╕рд╛рди рдПрдХреНрд╕реЗрд╕ рдХреЗ рд▓рд┐рдП рдПрдХ рдбрд┐рдХреНрд╢рдирд░реА рдореЗрдВ рд░рдЦрд╛ рдЬрд╛рддрд╛ рд╣реИред
from llama_index.core import SimpleDirectoryReader
# Document titles and metadata
article_titles = ["How to Do Great Work", "Having Kids", "How to Lose Time and Money"]
article_metadatas = {
"How to Do Great Work": {
"category": "self-help",
},
"Having Kids": {
"category": "self-help",
},
"How to Lose Time and Money": {
"category": "self-help",
},
}
# Load documents and update with metadata
docs_dict = {}
for title in article_titles:
doc = SimpleDirectoryReader(
input_files=[f"llamaindex-data/{title}.txt"]
).load_data()[0]
doc.metadata.update(article_metadatas[title])
docs_dict[title] = doc
docs_dict
рдкрдврд╝рдиреЗ рдореЗрдВ рдЖрд╕рд╛рдиреА рдХреЗ рд▓рд┐рдП, рдореИрдВ рдиреАрдЪреЗ рдЖрдЙрдЯрдкреБрдЯ рдХреЛ рдЫреЛрдЯрд╛ рдХрд░ рд░рд╣рд╛/рд░рд╣реА рд╣реВрдБ:
{'How to Do Great Work': Document(id_='e26a2fcc-77d2-43e8-968b-f893944907dc', embedding=None, metadata={'file_path': 'llamaindex-data/How to Do Great Work.txt', 'file_name': 'How to Do Great Work.txt', 'file_type': 'text/plain', 'file_size': 59399, 'creation_date': '2024-09-18', 'last_modified_date': '2024-09-18', 'category': 'self-help'}, excluded_embed_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], excluded_llm_metadata_keys=['file_name', 'file_type', 'file_size', 'creation_date', 'last_modified_date', 'last_accessed_date'], relationships={}, text='July 2023\\n\\nIf you collected lists of techniques for doing great work in a lot of different fields, what would the intersection look like? I decided to find out by making it.\\n\\nPartly my goal was to create a guide that could be used by someone working in any field. But I was also curious about the shape of the intersection. And one thing this exercise shows is that it does have a definite shape; it\\'s not just a point labelled "work hard."\\n\\nThe following recipe assumes you\\'re very ambitious.\\n\\n\\n\\n\\n\\nThe first step is to decide what to work on. The work you choose needs to have three qualities: it has to be something you have a natural aptitude for, that you have a deep interest in, and that offers scope to do great work.\\n\\nIn practice you don\\'t have to worry much about the third criterion. Ambitious people are if anything already too conservative about it. So all you need to do is find something you have an aptitude for and great interest in. [1]\\n\\nThat sounds straightforward, but it\\'s often quite difficult. When you\\'re young you don\\'t know what you\\'re good at or what different kinds of work are like. Some kinds of work you end up doing may not even exist yet. So while some people know what they want to do at 14, most have to figure it out.\\n\\nThe way to figure out what to work on is by working. If you\\'re not sure what to work on, guess. But pick something and get going. You\\'ll probably guess wrong some of the time, but that\\'s fine. It\\'s good to know about multiple things; some of the biggest discoveries come from noticing connections between different fields.\\n\\n
тАж
(truncated)
рдЪрд░рдг 2: LLM рдФрд░ chunking рд╕реЗрдЯ рдХрд░реЗрдВ
рдЗрд╕рдХреЗ рдмрд╛рдж, рд╣рдо OpenAI рдХреЗ GPT-4o Mini рдХреЛ LLM рдХреЗ рд░реВрдк рдореЗрдВ рдЗрдирд┐рд╢рд┐рдпрд▓рд╛рдЗрдЬрд╝ рдХрд░рддреЗ рд╣реИрдВ рдФрд░ рд╡рд╛рдХреНрдп-рд╡рд┐рднрд╛рдЬрдХ рдХреЛ рдХреЙрдиреНрдлрд╝рд┐рдЧрд░ рдХрд░рддреЗ рд╣реИрдВ рддрд╛рдХрд┐ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝реЛрдВ рдХреЛ рдПрдореНрдмреЗрдбрд┐рдВрдЧ рдХреЗ рд▓рд┐рдП рдЫреЛрдЯреЗ рдЯреБрдХрдбрд╝реЛрдВ рдореЗрдВ рдмрд╛рдБрдЯрд╛ рдЬрд╛ рд╕рдХреЗред рд╣рдо рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдХреЛ рдЯреНрд░реИрдХ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ callback рдореИрдиреЗрдЬрд░ рднреА рд╕реЗрдЯ рдХрд░рддреЗ рд╣реИрдВред
from llama_index.llms.openai import OpenAI
from llama_index.core.callbacks import LlamaDebugHandler, CallbackManager
from llama_index.core.node_parser import SentenceSplitter
# Initialize LLM and chunk splitter
llm = OpenAI("gpt-4o-mini")
callback_manager = CallbackManager([LlamaDebugHandler()])
splitter = SentenceSplitter(chunk_size=256)
рдЪрд░рдг 3: рд╡реЗрдХреНрдЯрд░ рдЗрдВрдбреЗрдХреНрд╕ рдмрдирд╛рдПрдБ рдФрд░ рд╕рд╛рд░рд╛рдВрд╢ рдЬрдирд░реЗрдЯ рдХрд░реЗрдВ
рдкреНрд░рддреНрдпреЗрдХ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЗ рд▓рд┐рдП, рд╣рдо рдПрдХ рд╡реЗрдХреНрдЯрд░ рдЗрдВрдбреЗрдХреНрд╕ рдмрдирд╛рддреЗ рд╣реИрдВ, рдЬреЛ рдмрд╛рдж рдореЗрдВ рд╕рдорд╛рдирддрд╛ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝-рдЯреБрдХрдбрд╝реЗ рдкреБрдирд░реНрдкреНрд░рд╛рдкреНрдд рдХрд░рдиреЗ рджреЗрддрд╛ рд╣реИред рдкреНрд░рддреНрдпреЗрдХ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЗ рд╕рд╛рд░рд╛рдВрд╢ LLM рджреНрд╡рд╛рд░рд╛ рдмрдирд╛рдП рдЬрд╛рддреЗ рд╣реИрдВред рдпреЗ рд╕рд╛рд░рд╛рдВрд╢ IndexNode рдХреЗ рд░реВрдк рдореЗрдВ рд╕рдВрдЧреНрд░рд╣реАрдд рд╣реЛрддреЗ рд╣реИрдВред
from llama_index.core import VectorStoreIndex, SummaryIndex
from llama_index.core.schema import IndexNode
# Define top-level nodes and vector retrievers
nodes = []
vector_query_engines = {}
vector_retrievers = {}
for title in article_titles:
# build vector index
vector_index = VectorStoreIndex.from_documents(
[docs_dict[title]],
transformations=[splitter],
callback_manager=callback_manager,
)
# define query engines
vector_query_engine = vector_index.as_query_engine(llm=llm)
vector_query_engines[title] = vector_query_engine
vector_retrievers[title] = vector_index.as_retriever(similarity_top_k=3)
# save summaries
out_path = Path("summaries") / f"{title}.txt"
if not out_path.exists():
# use LLM-generated summary
summary_index = SummaryIndex.from_documents(
[docs_dict[title]], callback_manager=callback_manager
)
summarizer = summary_index.as_query_engine(
response_mode="tree_summarize", llm=llm
)
response = await summarizer.aquery(
f"Give me a summary of {title}"
)
article_summary = response.response
Path("summaries").mkdir(exist_ok=True)
with open(out_path, "w") as fp:
fp.write(article_summary)
else:
with open(out_path, "r") as fp:
article_summary = fp.read()
print(f"**Summary for {title}: {article_summary}")
node = IndexNode(text=article_summary, index_id=title)
nodes.append(node)
**********
Trace: index_construction
**********
**Summary for How to Do Great Work: The essence of doing great work revolves around a few key principles. First, it's crucial to choose a field that aligns with your natural aptitudes and deep interests, as this will drive your motivation and creativity. Engaging in your own projects and maintaining a sense of excited curiosity are vital for discovering new ideas and making significant contributions.
Learning enough to reach the frontiers of knowledge in your chosen field allows you to identify gaps and explore them, often leading to innovative breakthroughs. Hard work is essential, but it should be fueled by genuine interest rather than mere diligence. Consistency and the willingness to embrace challenges, including the risk of failure, are important for growth and discovery.
Collaboration with high-quality colleagues can enhance your work, as they can provide insights and encouragement. Maintaining morale is also crucial; a positive mindset can help you navigate setbacks and keep you focused on your goals.
Ultimately, curiosity serves as the driving force behind great work, guiding you through the process of exploration and discovery. By nurturing your curiosity and being open to new experiences, you can uncover unique opportunities and make meaningful contributions in your field.
**********
Trace: index_construction
**********
**Summary for Having Kids: The piece reflects on the author's transformation in perspective regarding parenthood. Initially apprehensive about having children, viewing parents as uncool and burdensome, the author experiences a profound shift after becoming a parent. The arrival of their first child triggers protective instincts and a newfound appreciation for children, leading to genuine joy in parenting moments that were previously overlooked.
The author acknowledges the challenges of parenthood, such as reduced productivity and ambition, as well as the necessity of adapting to a child's schedule. Despite these challenges, the author finds that the happiness and meaningful moments shared with children far outweigh the difficulties. The narrative emphasizes that while parenting can be demanding, it also brings unexpected joy and fulfillment, ultimately leading to a richer life experience.
**********
Trace: index_construction
**********
**Summary for How to Lose Time and Money: The piece discusses the author's reflections on wealth and time management after selling a startup. It emphasizes that losing wealth often stems from poor investments rather than excessive spending, as the latter triggers alarms in our minds. The author highlights the need to develop new awareness to avoid bad investments, which can be less obvious than overspending on luxuries. Similarly, when it comes to time, the most significant loss occurs not through leisure activities but through engaging in unproductive work that feels legitimate, like managing emails. The author argues that modern complexities require us to recognize and avoid these deceptive traps that mimic productive behavior but ultimately lead to wasted time.
рдЬреИрд╕рд╛ рдХрд┐ рдЖрдк рджреЗрдЦ рд╕рдХрддреЗ рд╣реИрдВ, рдЕрдм рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рддреАрди рдиреЛрдб рд╣реИрдВ, рдЬрд┐рдирдореЗрдВ рд╕реЗ рдкреНрд░рддреНрдпреЗрдХ рдХрд┐рд╕реА рдПрдХ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЗ рд╕рд╛рд░рд╛рдВрд╢ рдХрд╛ рдкреНрд░рддрд┐рдирд┐рдзрд┐рддреНрд╡ рдХрд░рддрд╛ рд╣реИред рдЗрд╕рдХреЗ рдЕрддрд┐рд░рд┐рдХреНрдд, рд╣рдорд╛рд░реЗ рдкрд╛рд╕ vector_retrievers рднреА рд╣реИрдВ, рдЬреЛ рдкреНрд░рддреНрдпреЗрдХ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреЗ рд▓рд┐рдП chunk рд╡реЗрдХреНрдЯрд░ рд╕рдВрдЧреНрд░рд╣реАрдд рдХрд░рддреЗ рд╣реИрдВред
print(nodes)
print('------'
print(vector_retrievers)
[IndexNode(id_='406d9927-c9e2-486f-9fc5-111efefc1649', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, text="The essence of doing great work revolves around a few key principles. First, it's crucial to choose a field that aligns with your natural aptitudes and deep interests, as this will drive your motivation and creativity. Engaging in your own projects and maintaining a sense of excited curiosity are vital for discovering new ideas and making significant contributions.\\n\\nLearning enough to reach the frontiers of knowledge in your chosen field allows you to identify gaps and explore them, often leading to innovative breakthroughs. Hard work is essential, but it should be fueled by genuine interest rather than mere diligence. Consistency and the willingness to embrace challenges, including the risk of failure, are important for growth and discovery.\\n\\nCollaboration with high-quality colleagues can enhance your work, as they can provide insights and encouragement. Maintaining morale is also crucial; a positive mindset can help you navigate setbacks and keep you focused on your goals.\\n\\nUltimately, curiosity serves as the driving force behind great work, guiding you through the process of exploration and discovery. By nurturing your curiosity and being open to new experiences, you can uncover unique opportunities and make meaningful contributions in your field.", mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n', index_id='How to Do Great Work', obj=None),
IndexNode(id_='8007fdd2-6617-4a76-95d7-79efef0700e7', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, text="The piece reflects on the author's transformation in perspective regarding parenthood. Initially apprehensive about having children, viewing parents as uncool and burdensome, the author experiences a profound shift after becoming a parent. The arrival of their first child triggers protective instincts and a newfound appreciation for children, leading to genuine joy in parenting moments that were previously overlooked. \\n\\nThe author acknowledges the challenges of parenthood, such as reduced productivity and ambition, as well as the necessity of adapting to a child's schedule. Despite these challenges, the author finds that the happiness and meaningful moments shared with children far outweigh the difficulties. The narrative emphasizes that while parenting can be demanding, it also brings unexpected joy and fulfillment, ultimately leading to a richer life experience.", mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n', index_id='Having Kids', obj=None),
IndexNode(id_='7e4dd169-eb28-4b2f-8a1a-ca1c5b85ac30', embedding=None, metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[], relationships={}, text="The piece discusses the author's reflections on wealth and time management after selling a startup. It emphasizes that losing wealth often stems from poor investments rather than excessive spending, as the latter triggers alarms in our minds. The author highlights the need to develop new awareness to avoid bad investments, which can be less obvious than overspending on luxuries. Similarly, when it comes to time, the most significant loss occurs not through leisure activities but through engaging in unproductive work that feels legitimate, like managing emails. The author argues that modern complexities require us to recognize and avoid these deceptive traps that mimic productive behavior but ultimately lead to wasted time.", mimetype='text/plain', start_char_idx=None, end_char_idx=None, text_template='{metadata_str}\\n\\n{content}', metadata_template='{key}: {value}', metadata_seperator='\\n', index_id='How to Lose Time and Money', obj=None)]
------
{'How to Do Great Work': <llama_index.core.indices.vector_store.retrievers.retriever.VectorIndexRetriever at 0x330afeeb0>,
'Having Kids': <llama_index.core.indices.vector_store.retrievers.retriever.VectorIndexRetriever at 0x33129c7c0>,
'How to Lose Time and Money': <llama_index.core.indices.vector_store.retrievers.retriever.VectorIndexRetriever at 0x32e8929a0>}
рдЪрд░рдг 4: рд╢реАрд░реНрд╖-рд╕реНрддрд░реАрдп рд╡реЗрдХреНрдЯрд░ рдЗрдВрдбреЗрдХреНрд╕ рдмрдирд╛рдПрдБ
рдЬрдм рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рд╕рд╛рд░рд╛рдВрд╢ (nodes) рд╣реЛрдВ, рддреЛ рд╣рдо рдПрдХ рд╢реАрд░реНрд╖-рд╕реНрддрд░реАрдп рд╡реЗрдХреНрдЯрд░ рдЗрдВрдбреЗрдХреНрд╕ рдФрд░ рд░рд┐рдЯреНрд░реАрд╡рд░ (top_vector_retriever) рдмрдирд╛ рд╕рдХрддреЗ рд╣реИрдВред рдпрд╣ рдЗрдВрдбреЗрдХреНрд╕ рд░рд┐рдЯреНрд░реАрд╡рд▓ рдкреНрд░рдХреНрд░рд┐рдпрд╛ рд╢реБрд░реВ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рд╛рд░рд╛рдВрд╢реЛрдВ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддрд╛ рд╣реИред рдЗрд╕рд╕реЗ рд╣рдо рд╡рд┐рд╕реНрддреГрдд рджрд╕реНрддрд╛рд╡реЗрдЬрд╝-рдЯреБрдХрдбрд╝реЛрдВ рдореЗрдВ рдЬрд╛рдиреЗ рд╕реЗ рдкрд╣рд▓реЗ рд╕рдмрд╕реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рд╕рд╛рд░рд╛рдВрд╢ рдвреВрдБрдв рдкрд╛рддреЗ рд╣реИрдВред
# Build top-level vector index from summary nodes
top_vector_index = VectorStoreIndex(
nodes, transformations=[splitter], callback_manager=callback_manager
)
# Set up a retriever for the top-level summaries
top_vector_retriever = top_vector_index.as_retriever(similarity_top_k=1)
top_vector_retriever
<llama_index.core.indices.vector_store.retrievers.retriever.VectorIndexRetriever at 0x32db715b0>
рдЪрд░рдг 5: Recursive retrieval рд╕реЗрдЯ рдХрд░реЗрдВ
рдЕрдм рдЬрдм рд╣рдорд╛рд░реЗ рдкрд╛рд╕ рд╢реАрд░реНрд╖-рд╕реНрддрд░реАрдп рд░рд┐рдЯреНрд░реАрд╡рд░ рдФрд░ рд╡реНрдпрдХреНрддрд┐рдЧрдд рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рд░рд┐рдЯреНрд░реАрд╡рд░ рджреЛрдиреЛрдВ рд╣реИрдВ, рддреЛ рд╣рдо recursive retriever рд╕реЗрдЯ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдпрд╣ рд╕реЗрдЯрдЕрдк рд╕рд┐рд╕реНрдЯрдо рдХреЛ рдкрд╣рд▓реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рд╕рд╛рд░рд╛рдВрд╢ рдкреНрд░рд╛рдкреНрдд рдХрд░рдиреЗ рдФрд░ рдлрд┐рд░ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХрддрд╛ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рд╡рд┐рд╢рд┐рд╖реНрдЯ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝-рдЯреБрдХрдбрд╝реЛрдВ рддрдХ рдЬрд╛рдиреЗ рдореЗрдВ рд╕рдХреНрд╖рдо рдмрдирд╛рддрд╛ рд╣реИред
from llama_index.core.retrievers import RecursiveRetriever
# Combine top-level retriever with individual document retrievers
recursive_retriever = RecursiveRetriever(
"vector",
retriever_dict={"vector": top_vector_retriever, **vector_retrievers},
verbose=True,
)
рдЪрд░рдг 6: Recursive retrieval рдХреНрд╡реЗрд░рд┐рдпрд╛рдБ рдЪрд▓рд╛рдПрдБ
рдЕрдВрддрддрдГ, рд╣рдо рдЕрдкрдиреЗ recursive retriever рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдХреБрдЫ рдирдореВрдирд╛ рдХреНрд╡реЗрд░рд┐рдпрд╛рдБ рдЪрд▓рд╛ рд╕рдХрддреЗ рд╣реИрдВред
# Run recursive retriever on sample queries
result = recursive_retriever.retrieve("should I have kids?")
for res in result:
print(res.node.get_content())
Retrieving with query id None: should I have kids?
Retrieved node with id, entering: Having Kids
Retrieving with query id Having Kids: should I have kids?
Retrieving text node: Do you have so little to spare?
And while having kids may be warping my present judgement, it hasn't overwritten my memory. I remember perfectly well what life was like before. Well enough to miss some things a lot, like the ability to take off for some other country at a moment's notice. That was so great. Why did I never do that?
See what I did there? The fact is, most of the freedom I had before kids, I never used. I paid for it in loneliness, but I never used it.
I had plenty of happy times before I had kids. But if I count up happy moments, not just potential happiness but actual happy moments, there are more after kids than before. Now I practically have it on tap, almost any bedtime.
People's experiences as parents vary a lot, and I know I've been lucky. But I think the worries I had before having kids must be pretty common, and judging by other parents' faces when they see their kids, so must the happiness that kids bring.
Retrieving text node: December 2019
Before I had kids, I was afraid of having kids. Up to that point I felt about kids the way the young Augustine felt about living virtuously. I'd have been sad to think I'd never have children. But did I want them now? No.
If I had kids, I'd become a parent, and parents, as I'd known since I was a kid, were uncool. They were dull and responsible and had no fun. And while it's not surprising that kids would believe that, to be honest I hadn't seen much as an adult to change my mind. Whenever I'd noticed parents with kids, the kids seemed to be terrors, and the parents pathetic harried creatures, even when they prevailed.
When people had babies, I congratulated them enthusiastically, because that seemed to be what one did. But I didn't feel it at all. "Better you than me," I was thinking.
Now when people have babies I congratulate them enthusiastically and I mean it. Especially the first one. I feel like they just got the best gift in the world.
Retrieving text node: Which meant I had to finish or I'd be taking away their trip to Africa. Maybe if I'm really lucky such tricks could put me net ahead. But the wind is there, no question.
On the other hand, what kind of wimpy ambition do you have if it won't survive having kids? Do you have so little to spare?
And while having kids may be warping my present judgement, it hasn't overwritten my memory. I remember perfectly well what life was like before. Well enough to miss some things a lot, like the ability to take off for some other country at a moment's notice. That was so great. Why did I never do that?
See what I did there? The fact is, most of the freedom I had before kids, I never used. I paid for it in loneliness, but I never used it.
I had plenty of happy times before I had kids. But if I count up happy moments, not just potential happiness but actual happy moments, there are more after kids than before. Now I practically have it on tap, almost any bedtime.
result = recursive_retriever.retrieve("How to buy more time?")
for res in result:
print(res.node.get_content())
Retrieving with query id None: How to buy more time?
Retrieved node with id, entering: How to Lose Time and Money
Retrieving with query id How to Lose Time and Money: How to buy more time?
Retrieving text node: Which is why people trying to sell you expensive things say "it's an investment."
The solution is to develop new alarms. This can be a tricky business, because while the alarms that prevent you from overspending are so basic that they may even be in our DNA, the ones that prevent you from making bad investments have to be learned, and are sometimes fairly counterintuitive.
A few days ago I realized something surprising: the situation with time is much the same as with money. The most dangerous way to lose time is not to spend it having fun, but to spend it doing fake work. When you spend time having fun, you know you're being self-indulgent. Alarms start to go off fairly quickly. If I woke up one morning and sat down on the sofa and watched TV all day, I'd feel like something was terribly wrong. Just thinking about it makes me wince. I'd start to feel uncomfortable after sitting on a sofa watching TV for 2 hours, let alone a whole day.
Retrieving text node: The solution is to develop new alarms. This can be a tricky business, because while the alarms that prevent you from overspending are so basic that they may even be in our DNA, the ones that prevent you from making bad investments have to be learned, and are sometimes fairly counterintuitive.
A few days ago I realized something surprising: the situation with time is much the same as with money. The most dangerous way to lose time is not to spend it having fun, but to spend it doing fake work. When you spend time having fun, you know you're being self-indulgent. Alarms start to go off fairly quickly. If I woke up one morning and sat down on the sofa and watched TV all day, I'd feel like something was terribly wrong. Just thinking about it makes me wince. I'd start to feel uncomfortable after sitting on a sofa watching TV for 2 hours, let alone a whole day.
And yet I've definitely had days when I might as well have sat in front of a TV all day тАФ days at the end of which, if I asked myself what I got done that day, the answer would have been: basically, nothing.
Retrieving text node: Investing bypasses those alarms. You're not spending the money; you're just moving it from one asset to another. Which is why people trying to sell you expensive things say "it's an investment."
The solution is to develop new alarms. This can be a tricky business, because while the alarms that prevent you from overspending are so basic that they may even be in our DNA, the ones that prevent you from making bad investments have to be learned, and are sometimes fairly counterintuitive.
A few days ago I realized something surprising: the situation with time is much the same as with money. The most dangerous way to lose time is not to spend it having fun, but to spend it doing fake work. When you spend time having fun, you know you're being self-indulgent. Alarms start to go off fairly quickly. If I woke up one morning and sat down on the sofa and watched TV all day, I'd feel like something was terribly wrong. Just thinking about it makes me wince.
рдирд┐рд╖реНрдХрд░реНрд╖
рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рд╕рд╛рд░рд╛рдВрд╢реЛрдВ рдФрд░ рдЕрдиреБрдХреНрд░рдореЛрдВ (hierarchies) рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ, recursive retrieval рдмрдбрд╝реЗ рдбреЗрдЯрд╛ рд╕реЗрдЯреНрд╕ рдХреЗ рд╕рд╛рде рдХрд╛рдо рдХрд░рддреЗ рд╕рдордп рднреА рдкреНрд░рд╛рдкреНрдд рдЯреБрдХрдбрд╝реЛрдВ рдХреЛ рдЕрдзрд┐рдХ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рдмрдирд╛рддрд╛ рд╣реИред рдмрдбрд╝реА рдорд╛рддреНрд░рд╛ рдореЗрдВ рдбреЗрдЯрд╛ рд╕рдВрднрд╛рд▓рдиреЗ рд╡рд╛рд▓реЗ рд╕рдВрдЧрдардиреЛрдВ рдХреЗ рд▓рд┐рдП, recursive retrieval рдЕрдзрд┐рдХ рд╕рдЯреАрдХ рд░рд┐рдЯреНрд░реАрд╡рд▓ рд╕рд┐рд╕реНрдЯрдо рдмрдирд╛рдиреЗ рдХреА рдПрдХ рд╡рд┐рд╢реНрд╡рд╕рдиреАрдп рд╡рд┐рдзрд┐ рд╣реИред
RAG рддрдХрдиреАрдХреЛрдВ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдФрд░ рдЬрд╛рдирдиреЗ рдХреЗ рд▓рд┐рдП, рдореИрдВ рдпреЗ рдмреНрд▓реЙрдЧ рд╕реБрдЭрд╛рддрд╛/рд╕реБрдЭрд╛рддреА рд╣реВрдБ:
- Corrective RAG (CRAG) рдХрд╛ LangGraph рдХреЗ рд╕рд╛рде рдЗрдореНрдкреНрд▓реАрдореЗрдВрдЯреЗрд╢рди
- Llama 3.1 8B, Ollama, рдФрд░ LangChain рдХреЗ рд╕рд╛рде RAG
- RAG рдХреЗ рд▓рд┐рдП рд░реА-рд░реИрдВрдХрд┐рдВрдЧ рдПрдЬреЗрдВрдЯ рдХреЗ рд░реВрдк рдореЗрдВ RankGPT
- рдиреЙрд▓реЗрдЬ рдЧреНрд░рд╛рдл рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ RAG рдЕрдиреБрдкреНрд░рдпреЛрдЧ рд▓рд╛рдЧреВ рдХрд░рдирд╛
- Transformers рдХреЗ рд╕рд╛рде Speculative RAG рдХрд╛ рдЗрдореНрдкреНрд▓реАрдореЗрдВрдЯреЗрд╢рди
рд░рд╛рдпрди рдПрдХ рд▓реАрдб рдбреЗрдЯрд╛ рд╕рд╛рдЗрдВрдЯрд┐рд╕реНрдЯ рд╣реИрдВ рдЬреЛ LLMs рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдПрдЖрдИ рдЕрдиреБрдкреНрд░рдпреЛрдЧ рдмрдирд╛рдиреЗ рдореЗрдВ рд╡рд┐рд╢реЗрд╖рдЬреНрдЮрддрд╛ рд░рдЦрддреЗ/рд░рдЦрддреА рд╣реИрдВред рд╡реЗ рдЗрдореНрдкреАрд░рд┐рдпрд▓ рдХреЙрд▓реЗрдЬ рд▓рдВрджрди рдореЗрдВ рдиреИрдЪреБрд░рд▓ рд▓реИрдВрдЧреНрд╡реЗрдЬ рдкреНрд░реЛрд╕реЗрд╕рд┐рдВрдЧ рдФрд░ рдиреЙрд▓реЗрдЬ рдЧреНрд░рд╛рдлреНрд╕ рдореЗрдВ рдкреАрдПрдЪрдбреА рдЙрдореНрдореАрджрд╡рд╛рд░ рд╣реИрдВ, рдЬрд╣рд╛рдБ рд╕реЗ рдЙрдиреНрд╣реЛрдВрдиреЗ рдХрдВрдкреНрдпреВрдЯрд░ рд╕рд╛рдЗрдВрд╕ рдореЗрдВ рдЕрдкрдирд╛ рдорд╛рд╕реНрдЯрд░тАЩрд╕ рднреА рдкреВрд░рд╛ рдХрд┐рдпрд╛ рд╣реИред рдбреЗрдЯрд╛ рд╕рд╛рдЗрдВрд╕ рдХреЗ рдЕрд▓рд╛рд╡рд╛, рд╡реЗ рд╕рд╛рдкреНрддрд╛рд╣рд┐рдХ Substack рдиреНрдпреВрдЬрд╝рд▓реЗрдЯрд░┬аThe Limitless Playbook рд▓рд┐рдЦрддреЗ рд╣реИрдВ, рдЬрд┐рд╕рдореЗрдВ рд╡реЗ рджреБрдирд┐рдпрд╛ рдХреЗ рдЕрдЧреНрд░рдгреА рд╡рд┐рдЪрд╛рд░рдХреЛрдВ рд╕реЗ рдПрдХ рдХреНрд░рд┐рдпрд╛рдиреНрд╡рдпрди рдпреЛрдЧреНрдп рд╡рд┐рдЪрд╛рд░ рд╕рд╛рдЭрд╛ рдХрд░рддреЗ рд╣реИрдВ рдФрд░ рд╕рдордп-рд╕рдордп рдкрд░ рдореВрд▓рднреВрдд рдПрдЖрдИ рдЕрд╡рдзрд╛рд░рдгрд╛рдУрдВ рдкрд░ рднреА рд▓рд┐рдЦрддреЗ рд╣реИрдВред

рдХрдИ RAG рдЕрдиреБрдкреНрд░рдпреЛрдЧреЛрдВ рдореЗрдВ, рд░рд┐рдЯреНрд░реАрд╡рд▓ рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдЖрдо рддреМрд░ рдкрд░ рдХрд╛рдлреА рд╕рд░рд▓ рд╣реЛрддреА рд╣реИред рджрд╕реНрддрд╛рд╡реЗрдЬрд╝реЛрдВ рдХреЛ рдкреНрд░рд╛рдпрдГ рдЯреБрдХрдбрд╝реЛрдВ рдореЗрдВ рдмрд╛рдБрдЯрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдПрдореНрдмреЗрдбрд┐рдВрдЧреНрд╕ рдореЗрдВ рдмрджрд▓рд╛ рдЬрд╛рддрд╛ рд╣реИ, рдФрд░ рдПрдХ рд╡реЗрдХреНрдЯрд░ рдбреЗрдЯрд╛рдмреЗрд╕ рдореЗрдВ рд╕рдВрдЧреНрд░рд╣реАрдд рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред рдЬрдм рдХреЛрдИ рдХреНрд╡реЗрд░реА рдХреА рдЬрд╛рддреА рд╣реИ, рддреЛ рд╕рд┐рд╕реНрдЯрдо рдЙрдирдХреА рдПрдореНрдмреЗрдбрд┐рдВрдЧреНрд╕ рдХреА рд╕рдорд╛рдирддрд╛ рдХреЗ рдЖрдзрд╛рд░ рдкрд░ рд╢реАрд░реНрд╖-k рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдЦреАрдВрдЪрддрд╛ рд╣реИред
рд╣рд╛рд▓рд╛рдВрдХрд┐, рдЗрд╕ рд╡рд┐рдзрд┐ рдХреА рдХреБрдЫ рдЦрд╛рдорд┐рдпрд╛рдБ рд╣реИрдВ, рд╡рд┐рд╢реЗрд╖рдХрд░ рдмрдбрд╝реЗ рд╕рдВрдЧреНрд░рд╣реЛрдВ рдореЗрдВред рдЯреБрдХрдбрд╝реЗ рд╕рдВрджрд░реНрднрд╣реАрди рд╣реЛ рд╕рдХрддреЗ рд╣реИрдВ, рдФрд░ рд╕рд┐рд╕реНрдЯрдо рд╣рдореЗрд╢рд╛ рд╕рдмрд╕реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рдЬрд╛рдирдХрд╛рд░реА рдирд╣реАрдВ рдирд┐рдХрд╛рд▓ рдкрд╛рддрд╛, рдЬрд┐рд╕рд╕реЗ рдкрд░рд┐рдгрд╛рдо рдХрдо рд╕рдЯреАрдХ рд╣реЛ рд╕рдХрддреЗ рд╣реИрдВред
Recursive retrieval рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдХреА рд╕рдВрд░рдЪрдирд╛ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рд░рд┐рдЯреНрд░реАрд╡рд▓ рдХреА рд╕рдЯреАрдХрддрд╛ рдмрдврд╝рд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╡рд┐рдХрд╕рд┐рдд рдХрд┐рдпрд╛ рдЧрдпрд╛ред рд╕реАрдзреЗ рдЯреБрдХрдбрд╝реЗ рдирд┐рдХрд╛рд▓рдиреЗ рдХреЗ рдмрдЬрд╛рдп, рдпрд╣ рдкрд╣рд▓реЗ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рд╕рд╛рд░рд╛рдВрд╢ рдкреНрд░рд╛рдкреНрдд рдХрд░рддрд╛ рд╣реИ рдФрд░ рдлрд┐рд░ рдЙрдирд╕реЗ рдЬреБрдбрд╝реЗ рдЯреБрдХрдбрд╝реЛрдВ рддрдХ рдЧрд╣рд░рд╛рдИ рдореЗрдВ рдЬрд╛рддрд╛ рд╣реИ, рдЬрд┐рд╕рд╕реЗ рдЕрдВрддрд┐рдо рд░рд┐рдЯреНрд░реАрд╡рд▓ рдкрд░рд┐рдгрд╛рдо рдЕрдзрд┐рдХ рдкреНрд░рд╛рд╕рдВрдЧрд┐рдХ рдмрдирддреЗ рд╣реИрдВред
рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ, рд╣рдо recursive retrieval рд╕рдордЭрд╛рдПрдБрдЧреЗ рдФрд░ LlamaIndex рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдЗрд╕реЗ рдЪрд░рдг-рджрд░-рдЪрд░рдг рд▓рд╛рдЧреВ рдХрд░рдирд╛ рд╕рд┐рдЦрд╛рдПрдБрдЧреЗред