Git Product home page Git Product logo

Comments (2)

dosubot avatar dosubot commented on June 29, 2024 2

To optimize the extract_titles() function and avoid redundant LLM calls when there is only one node per document, you can modify the function as follows:

async def extract_titles(self, nodes_by_doc_id: Dict) -> Dict:
    titles_by_doc_id = {}
    for key, nodes in nodes_by_doc_id.items():
        if len(nodes) == 1:
            # Directly use the title from the single node
            titles_by_doc_id[key] = await self.llm.apredict(
                PromptTemplate(template=self.node_template),
                context_str=cast(TextNode, nodes[0]).text,
            )
        else:
            title_candidates = await self.get_title_candidates(nodes)
            combined_titles = ", ".join(title_candidates)
            titles_by_doc_id[key] = await self.llm.apredict(
                PromptTemplate(template=self.combine_template),
                context_str=combined_titles,
            )
    return titles_by_doc_id

This modification checks if there is only one node for a document and directly uses the title from that node, avoiding the need to combine multiple titles. This approach leverages the node_template for single nodes and the combine_template for multiple nodes, as described in the TitleExtractor class [1][2].

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

from llama_index.

erlebach avatar erlebach commented on June 29, 2024

My comment was meant for the maintainers of the repo.

from llama_index.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.