'use strict';

var chunk6Z7D7CA3_cjs = require('./chunk-6Z7D7CA3.cjs');

// src/relevance/cohere/index.ts
var CohereRelevanceScorer = class {
  model;
  apiKey;
  constructor(model, apiKey) {
    console.warn(
      'CohereRelevanceScorer exported from @mastra/core is deprecated. Please import from "@mastra/rag" instead.'
    );
    this.apiKey = apiKey;
    this.model = model;
  }
  async getRelevanceScore(query, text) {
    const response = await fetch(`https://api.cohere.com/v2/rerank`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${this.apiKey}`
      },
      body: JSON.stringify({
        query,
        documents: [text],
        model: this.model,
        top_n: 1
      })
    });
    if (!response.ok) {
      throw new Error(`Cohere API error: ${response.status} ${await response.text()}`);
    }
    const data = await response.json();
    const relevanceScore = data.results[0]?.relevance_score;
    if (!relevanceScore) {
      throw new Error("No relevance score found on Cohere response");
    }
    return relevanceScore;
  }
};

// src/relevance/relevance-score-provider.ts
function createSimilarityPrompt(query, text) {
  return `Rate the semantic similarity between the following the query and the text on a scale from 0 to 1 (decimals allowed), where 1 means exactly the same meaning and 0 means completely different:

Query: ${query}

Text: ${text}

Relevance score (0-1):`;
}

// src/relevance/mastra-agent/index.ts
var MastraAgentRelevanceScorer = class {
  agent;
  constructor(name, model) {
    this.agent = new chunk6Z7D7CA3_cjs.Agent({
      name: `Relevance Scorer ${name}`,
      instructions: `You are a specialized agent for evaluating the relevance of text to queries.
Your task is to rate how well a text passage answers a given query.
Output only a number between 0 and 1, where:
1.0 = Perfectly relevant, directly answers the query
0.0 = Completely irrelevant
Consider:
- Direct relevance to the question
- Completeness of information
- Quality and specificity
Always return just the number, no explanation.`,
      model
    });
  }
  async getRelevanceScore(query, text) {
    const prompt = createSimilarityPrompt(query, text);
    const model = await this.agent.getModel();
    let response;
    if (model.specificationVersion === "v2") {
      const responseText = await this.agent.generateVNext(prompt);
      response = responseText.text;
    } else {
      const responseText = await this.agent.generate(prompt);
      response = responseText.text;
    }
    return parseFloat(response);
  }
};

exports.CohereRelevanceScorer = CohereRelevanceScorer;
exports.MastraAgentRelevanceScorer = MastraAgentRelevanceScorer;
exports.createSimilarityPrompt = createSimilarityPrompt;
//# sourceMappingURL=chunk-CDLIHAX2.cjs.map
//# sourceMappingURL=chunk-CDLIHAX2.cjs.map