> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Precision

> Measure the percentage of relevant chunks in your retrieved context to evaluate retrieval quality in RAG systems

export const DefinitionCard = ({children}) => {
  return <Card variant="secondary">
    <div style={{
    padding: '0.5rem',
    border: '5px solid var(--primary-light)',
    borderRadius: '0.5rem',
    fontSize: '1.3rem',
    lineHeight: '1.4',
    boxShadow: '0 0 10px 10px var(--primary-light)'
  }}>
        {children}
      </div>

</Card>;
};

export const Scale = ({low, mid, high, lowLabel = "Low", midLabel = "Mid", highLabel = "High", lowDescription, midDescription, highDescription, midColor = "yellow", inverted = false}) => {
  const lowColor = inverted ? "green" : "red";
  const highColor = inverted ? "red" : "green";
  const gradientId = inverted ? "greenToRed" : "redToGreen";
  return <div style={{
    display: 'flex',
    flexDirection: 'column',
    width: '100%'
  }}>
      <svg width="100%" height="30" style={{
    marginBottom: '8px'
  }}>
        <defs>
          <linearGradient id={gradientId} x1="0%" y1="0%" x2="100%" y2="0%">
            <stop offset="0%" stopColor={lowColor} />
            <stop offset="100%" stopColor={highColor} />
          </linearGradient>
        </defs>
        <rect width="100%" height="100%" fill={`url(#${gradientId})`} rx="4" ry="4" />
      </svg>

      <div style={{
    display: 'flex',
    justifyContent: 'space-between',
    width: '100%',
    marginBottom: '16px'
  }}>
        <p style={{
    margin: 0,
    fontSize: '12px'
  }}>{low}</p>
        {mid && <p style={{
    margin: 0,
    fontSize: '12px'
  }}>{mid}</p>}
        <p style={{
    margin: 0,
    fontSize: '12px'
  }}>{high}</p>
      </div>

      <div style={{
    display: 'flex',
    justifyContent: 'space-between',
    width: '100%'
  }}>
        <div style={{
    maxWidth: '40%'
  }}>
          <div style={{
    display: 'flex',
    alignItems: 'center',
    marginBottom: '4px'
  }}>
            <div style={{
    width: '12px',
    height: '12px',
    backgroundColor: lowColor,
    borderRadius: '50%',
    marginRight: '8px'
  }}></div>
            <p style={{
    margin: 0,
    fontWeight: 'bold',
    fontSize: '14px'
  }}>{lowLabel}</p>
          </div>
          {lowDescription && <p style={{
    margin: 0,
    fontSize: '14px',
    color: '#666',
    maxWidth: '250px',
    lineHeight: '1.4'
  }}>{lowDescription}</p>}
        </div>
        {mid && <div style={{
    maxWidth: '40%',
    textAlign: 'center'
  }}>
            <div style={{
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    marginBottom: '4px'
  }}>
              <div style={{
    width: '12px',
    height: '12px',
    backgroundColor: midColor,
    borderRadius: '50%',
    marginRight: '8px'
  }}></div>
              <p style={{
    margin: 0,
    fontWeight: 'bold',
    fontSize: '14px'
  }}>{midLabel}</p>
            </div>
            {midDescription && <p style={{
    margin: 0,
    fontSize: '14px',
    color: '#666',
    maxWidth: '250px',
    textAlign: 'center',
    lineHeight: '1.4'
  }}>{midDescription}</p>}
          </div>}


        <div style={{
    maxWidth: '40%',
    textAlign: 'right'
  }}>
          <div style={{
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'flex-end',
    marginBottom: '4px'
  }}>
            <p style={{
    margin: 0,
    fontWeight: 'bold',
    fontSize: '14px'
  }}>{highLabel}</p>
            <div style={{
    width: '12px',
    height: '12px',
    backgroundColor: highColor,
    borderRadius: '50%',
    marginLeft: '8px'
  }}></div>
          </div>
          {highDescription && <p style={{
    margin: 0,
    fontSize: '14px',
    color: '#666',
    maxWidth: '250px',
    marginLeft: 'auto',
    lineHeight: '1.4'
  }}>{highDescription}</p>}
        </div>
      </div>
    </div>;
};

<DefinitionCard>
  <strong>Context Precision</strong> measures the percentage of retrieved chunks that are relevant to the user's query, helping identify how much noise or unwanted information was retrieved.
</DefinitionCard>

Context Precision is a continuous metric ranging from 0 to 1:

<Scale low="0" lowLabel="Low Precision" high="1" highLabel="High Precision" lowDescription="Few or no retrieved chunks are relevant to the query" highDescription="Most or all retrieved chunks are relevant to the query" />

This metric helps evaluate the quality of retrieval systems by measuring how many of the retrieved chunks actually contain useful information for answering the query. Higher Context Precision indicates that the retrieval system is successfully identifying and returning relevant content with minimal noise.

## Calculation method

Context Precision is computed using [Chunk Relevance](/concepts/metrics/rag/retrieval-quality/chunk-relevance) scores:

<Steps>
  <Step title="Chunk Relevance Calculation">
    First, [Chunk Relevance](/concepts/metrics/rag/retrieval-quality/chunk-relevance) is computed for each retrieved chunk, producing a binary classification (Relevant or Not Relevant) for each chunk.
  </Step>

  <Step title="Numerator Calculation">
    The numerator is calculated as the sum of (1.0 if the chunk is relevant, else 0.0) divided by N, where N is the position index starting from 1 (position 1, 2, 3, etc.).
  </Step>

  <Step title="Denominator Calculation">
    The denominator is the sum of 1/N for all chunks, where N is the position index starting from 1 (position 1, 2, 3, etc.).
  </Step>

  <Step title="Final Score">
    Context Precision is computed as the ratio of the numerator to the denominator, ensuring the metric ranges from 0 to 1.
  </Step>
</Steps>

## Understanding context precision

<Card>
  <div style={{display: 'flex', alignItems: 'center', gap: '0.5rem', marginBottom: '0.75rem'}}>
    <div style={{fontSize: '1.25rem', color: 'var(--primary-color)'}}>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z" />

        <path d="m9 12 2 2 4-4" />
      </svg>
    </div>

    <h3 style={{margin: 0, fontSize: '1.25rem', fontWeight: '600'}}>Example Scenario</h3>
  </div>

  This example illustrates Context Precision:

  <div style={{ marginTop: "1rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>User query:</strong> "What are the health benefits of green tea?"
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Retrieved chunks (10 total):</strong>

    <ul style={{ marginTop: "0.5rem" }}>
      <li>Position 1: "Green tea contains antioxidants..." (Relevant)</li>
      <li>Position 2: "Green tea may help with weight loss..." (Relevant)</li>
      <li>Position 3: "Black tea is produced by oxidizing..." (Not Relevant)</li>
      <li>Position 4: "Studies suggest green tea..." (Relevant)</li>
      <li>Positions 5-10: Various other chunks (mix of Relevant and Not Relevant)</li>
    </ul>
  </div>

  <div style={{ marginTop: "1rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Analysis:</strong> If 3 out of 10 chunks are relevant, Context Precision calculates the score based on which chunks are relevant and their positions. This helps identify how much noise or unwanted information was retrieved.
  </div>
</Card>

<Note type="info">
  Context Precision is differentiated from [Precision @ K](/concepts/metrics/rag/retrieval-quality/precision-at-k): Context Precision considers all retrieved chunks to measure noise in retrieval, while Precision @ K evaluates precision at a specific rank K and helps assess ranking quality.
</Note>

## Optimizing your RAG pipeline

<Card>
  <div style={{display: 'flex', alignItems: 'center', gap: '0.5rem', marginBottom: '0.75rem'}}>
    <div style={{fontSize: '1.25rem', color: 'var(--primary-color)'}}>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <path d="M12 20h9" />

        <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" />
      </svg>
    </div>

    <h3 style={{margin: 0, fontSize: '1.25rem', fontWeight: '600'}}>Addressing Low Context Precision Scores</h3>
  </div>

  When Context Precision scores are low, it indicates that many retrieved chunks are not relevant to the query, meaning there is significant noise in the retrieved results. To improve the system:

  <div style={{ marginTop: "1rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Improve retrieval quality:</strong> Refine embedding models, similarity search algorithms, or retrieval parameters to better match queries with relevant content.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Implement reranking:</strong> Use a reranking model to improve the order of retrieved chunks, ensuring the most relevant ones appear first.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Adjust Top K:</strong> If precision is consistently low, consider reducing the number of chunks retrieved (Top K) to focus on higher-quality results.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Analyze retrieval patterns:</strong> Examine which types of queries or content lead to low precision scores to identify systematic issues.
  </div>
</Card>

## Comparing Context Precision and Precision @ K

<Card>
  <div style={{display: 'flex', alignItems: 'center', gap: '0.5rem', marginBottom: '0.75rem'}}>
    <div style={{fontSize: '1.25rem', color: 'var(--primary-color)'}}>
      <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
        <path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z" />

        <path d="m9 12 2 2 4-4" />
      </svg>
    </div>

    <h3 style={{margin: 0, fontSize: '1.25rem', fontWeight: '600'}}>Understanding Metric Combinations</h3>
  </div>

  Different combinations of Context Precision and Precision @ K scores reveal different aspects of retrieval system performance:

  <div style={{ marginTop: "1rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>High Context Precision, High Precision @ K:</strong> The retrieval system is performing well overall. Most retrieved chunks are relevant, and the ranking is effective, with relevant chunks appearing in the top positions. This indicates minimal noise and good ranking quality.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>High Context Precision, Low Precision @ K:</strong> While the overall retrieval contains mostly relevant chunks (low noise), the ranking is poor. Relevant chunks are distributed throughout the retrieved set rather than concentrated in the top K positions. This suggests the retrieval system finds relevant content but needs better ranking or reranking.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Low Context Precision, High Precision @ K:</strong> The top K positions contain mostly relevant chunks (good ranking), but the overall retrieved set has significant noise. This indicates that while the ranking algorithm prioritizes relevant content effectively, the retrieval system is bringing back too many irrelevant chunks beyond the top K. Consider reducing Top K or improving retrieval quality.
  </div>

  <div style={{ marginTop: "0.75rem", paddingTop: "0.75rem", borderTop: "1px solid rgba(209, 213, 219, 0.33)" }}>
    <strong>Low Context Precision, Low Precision @ K:</strong> Both metrics indicate problems. The retrieval system has high noise (many irrelevant chunks) and poor ranking (relevant chunks are not in top positions). This suggests fundamental issues with both retrieval quality and ranking that need to be addressed.
  </div>
</Card>

### Reading Context Precision with Context Relevance

* **High Context Precision & High Context Relevance**: Most retrieved chunks are relevant and, together, contain everything needed to answer the query — you're in a good place; focus on generation quality next.
* **High Context Precision & Low Context Relevance**: Retrieved chunks are mostly on-topic but still don't cover all required information — widen retrieval (increase Top K, use an alternate retriever, or add data sources).
* **Low Context Precision & High Context Relevance**: The necessary information is there but buried in noise — keep your recall and reduce irrelevant chunks via better filters, reranking, or a smaller Top K.
* **Low Context Precision & Low Context Relevance**: Retrieval is both noisy and insufficient — you likely need deeper changes to embeddings, indexing strategy, or how queries are formed.

## Best practices

<CardGroup cols={2}>
  <Card title="Use for Retrieval Assessment" icon="chart-line">
    Context Precision helps evaluate the overall quality of retrieval system results and determine how accurately they adhere to queries.
  </Card>

  <Card title="Combine with Precision @ K" icon="link">
    Context Precision works alongside [Precision @ K](/concepts/metrics/rag/retrieval-quality/precision-at-k) to understand both overall precision and precision at specific ranks.
  </Card>

  <Card title="Monitor Retrieval Quality" icon="chart-line">
    Tracking Context Precision helps identify patterns in retrieval noise and understand how much unwanted information is being retrieved.
  </Card>

  <Card title="Optimize Retrieval Parameters" icon="sliders">
    Context Precision scores guide adjustments to Top K values, similarity thresholds, and reranking strategies.
  </Card>
</CardGroup>

<Note>
  When optimizing for Context Precision, the metric helps identify how much noise or unwanted information is present in the retrieved chunks, enabling improvements to retrieval quality.
</Note>
