rahmansahinler1 / ragchat_local

ragchat is a chatbot that gives you most up to date iformation with resources in your documents
MIT License
1 stars 0 forks source link

Vector Search Confidence Level Thresholds #30

Open rahmansahinler1 opened 1 month ago

rahmansahinler1 commented 1 month ago

Description To increase response capability and decrease hallucinitation improved searching processes will be added. Added features 1- Minimum match threshold 2- low/ medium / high threshold levels

Workflow 1- Increase the number of returned vectors from 5 to 20 2- Find the minimum match threshold based on test - v0.1 3- Find the low/ medium/ high threshold levels 4- Implement the logic to filter out vectors 5- Implement the logic for classify the vectors 6- Add this information to response generation pipeline 7- Adapt prompt generation accoring to these information

Acceptance Criteria Adapted response generation based on confidence levels

ozgurnsahin commented 3 weeks ago

Confidence attributing code: distance_dict = { "distances" : [], "confidence" : [] }

results = self.rf.user_query_process(query=user_query)

    query_vector = self.ef.create_vector_embedding_from_query(query=user_query)
    D, I = globals.index.search(query_vector, 20)
    globals.test_dict["distances"] = D[0]
    distance_dict["distances"] = D[0]
    for i in range(len(distance_dict["distances"])):
        if distance_dict["distances"][i] <= 0.42:
            distance_dict["confidence"].append("High")
        elif distance_dict["distances"][i]<= 0.66:
            distance_dict["confidence"].append("Mid")
        else:
            distance_dict["confidence"].append("Low")
    widen_sentences = self.widen_sentences(window_size=1, convergence_vector=I[0])

    context = ''
    for i in range(len(widen_sentences)):               
        template = f"""
        Context{i}: {widen_sentences[i]}
        """
        context += template

    confidence = ''
    for i,value in enumerate(distance_dict["confidence"]):               
        temp = f"""
        Confidence{i}: {value}
        """ 
        confidence += temp