Class: Langchain::Evals::Ragas::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/langchain/evals/ragas/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(llm:) ⇒ Main

Returns a new instance of Main.



11
12
13
# File 'lib/langchain/evals/ragas/main.rb', line 11

def initialize(llm:)
  @llm = llm
end

Instance Attribute Details

#llmObject (readonly)

Returns the value of attribute llm.



9
10
11
# File 'lib/langchain/evals/ragas/main.rb', line 9

def llm
  @llm
end

Instance Method Details

#score(question:, answer:, context:) ⇒ Hash

Returns the RAGAS scores, e.g.:

ragas_score: 0.6601257446503674,
answer_relevance_score: 0.9573145866787608,
context_relevance_score: 0.6666666666666666,
faithfulness_score: 0.5

Parameters:

  • question (String)

    Question

  • answer (String)

    Answer

  • context (String)

    Context

Returns:

  • (Hash)

    RAGAS scores



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/langchain/evals/ragas/main.rb', line 27

def score(question:, answer:, context:)
  answer_relevance_score = answer_relevance.score(question: question, answer: answer)
  context_relevance_score = context_relevance.score(question: question, context: context)
  faithfulness_score = faithfulness.score(question: question, answer: answer, context: context)

  {
    ragas_score: ragas_score(answer_relevance_score, context_relevance_score, faithfulness_score),
    answer_relevance_score: answer_relevance_score,
    context_relevance_score: context_relevance_score,
    faithfulness_score: faithfulness_score
  }
end