Find answers from the community

Updated 3 months ago

Hello, this time i'm not facing an issue

Hello, this time i'm not facing an issue, i need to do rag with this query but i don't really understand how it works in the docs. Can you help me doing rag? Here is my query :

Plain Text
        mongodb_client = pymongo.MongoClient(_mongoURI)
        store = MongoDBAtlasVectorSearch(mongodb_client, db_name=indexName)

        # Initialisation de l'index via les index sur MongoDB Atlas
        # Et inversement, commenter/décommenter si on veut juste query l'index existant
        # build index
        index = VectorStoreIndex.from_vector_store(store)


        # configure retriever
        retriever = VectorIndexRetriever(
            index=index,
        )
        # configure response synthesizer
        response_synthesizer = get_response_synthesizer(
            response_mode= ResponseMode.TREE_SUMMARIZE,
        )
        # Template obligatoire du system prompt définissant le comprtement du LLM)

        qa_template = Prompt(requestDTO.get_system_template())
        
        if not qa_template or qa_template == "" or qa_template == None:
            responseDTO = ServiceQueryResponse.ServiceQueryResponseDTO(True, "Un historique de type 'System' est obligatoire.", None)        
            return GenerateQueryResponse(requestDTO, responseDTO), 400
        
        # assemble query engine
        query_engine = RetrieverQueryEngine(
            retriever=retriever,
            response_synthesizer=response_synthesizer,
        )

        #query_engine = query_engine.query(similarity_top_k=requestDTO.LinkNumber,text_qa_template=qa_template)


        # Partie permettant de créer la réponse

        query_engine = index.as_query_engine(similarity_top_k=requestDTO.LinkNumber,text_qa_template=qa_template)
        query_text = requestDTO.Prompt
        gpt_result = query_engine.query(query_text)



        resultDTO = ServiceQueryResponse.ServiceQueryResponseResultDTO(gpt_result.response, answer.message.content, [])
        
        for item in gpt_result.source_nodes:
            node = ServiceQueryResponse.ServiceQueryResponseNodeDTO(item.node.extra_info.get("file_name"), item.node.extra_info.get("page_label"), item.node.text, item.score)
            resultDTO.Nodes.append(node)



        # Construction de la réponse
        responseDTO = ServiceQueryResponse.ServiceQueryResponseDTO(False, None, resultDTO)
        # Terminée, on envoi la réponse définitive

        return GenerateQueryResponse(requestDTO, responseDTO), 200
W
1 comment
RAG comprises of the following things that you need to understand first.
  • Indexing
  • Retrievers
  • Query engines
Indexing:
In this step your data in converted into embeddings for easy implementation of algorithm such as cosine similarity for finding nearest data with your query.

Retrievers:
Retrievers are basically used to retrieve the nearest similar context from your total embeddings based on your topK value.

This does not uses llm in this step. only retrieves the nodes from your total nodes.

Query engines:
Query engines is the combination of retriver + llm. In this once you add the query, it will first extract related nodes and then pass it to LLM to form the final answer.

I hope this clears your doubt
Add a reply
Sign up and join the conversation on Discord