class_docstr: This Completion Function uses embeddings to retrieve the top k relevant docs from a dataset to the prompt, then adds them to the context before calling the completion.
class_docstr_tok: ["This","Completion","Function","uses","embeddings","to","retrieve","the","top","k","relevant","docs","from","a","dataset","to","the","prompt",",","then","adds","them","to","the","context","before","calling","the","completion","."]
docstr: Args:
      retrieval_template: The template to use for the retrieval. The task prompt will be added to the end of this template.
      k: The number of docs to retrieve from the dataset.
      completion_fn: The completion function to use for the retrieval.
      embeddings_and_text_path: The path to a CSV containing "text" and "embedding" columns.
      registry: Upstream callers may pass in a registry to use.
      registry_path: The path to a registry file to add to default registry.
      _kwargs: Additional arguments to pass to the completion function instantiation.
docstr_tok: ["Args",":","retrieval_template",":","The","template","to","use","for","the","retrieval",".","The","task","prompt","will","be","added","to","the","end","of","this","template",".","k",":","The","number","of","docs","to","retrieve","from","the","dataset",".","completion_fn",":","The","completion","function","to","use","for","the","retrieval",".","embeddings_and_text_path",":","The","path","to","a","CSV","containing","``","text","''","and","``","embedding","''","columns",".","registry",":","Upstream","callers","may","pass","in","a","registry","to","use",".","registry_path",":","The","path","to","a","registry","file","to","add","to","default","registry",".","_kwargs",":","Additional","arguments","to","pass","to","the","completion","function","instantiation","."]
code: def __init__(
      self,
      completion_fn: str,
      embeddings_and_text_path: str,
      retrieval_template: str = DEFAULT_RETRIEVAL_TEMPLATE,
      k: int = 4,
      embedding_model: str = "text-embedding-ada-002",
      registry: Optional[Registry] = None,
      registry_path: Optional[str] = None,
      **_kwargs: Any,
  ) -> None:
      """
      Args:
          retrieval_template: The template to use for the retrieval. The task prompt will be added to the end of this template.
          k: The number of docs to retrieve from the dataset.
          completion_fn: The completion function to use for the retrieval.
          embeddings_and_text_path: The path to a CSV containing "text" and "embedding" columns.
          registry: Upstream callers may pass in a registry to use.
          registry_path: The path to a registry file to add to default registry.
          _kwargs: Additional arguments to pass to the completion function instantiation.
      """
      registry = Registry() if not registry else registry
      if registry_path:
          registry.add_registry_paths(registry_path)
  
      self.embeddings_df = load_embeddings(embeddings_and_text_path)
  
      self.embedding_model = embedding_model
      self.k = k
  
      self.retrieval_template = retrieval_template
      self.completion_fn_instance = registry.make_completion_fn(
          completion_fn
      )
  
file_path: evals/evals/completion_fns/retrieval.py
imports: import os
  from ast import literal_eval
  from typing import Any, Optional, Union
  import numpy
  import pandas
  from openai import OpenAI
  from evals.api import CompletionFn, CompletionResult
  from evals.prompt.base import ChatCompletionPrompt, CompletionPrompt
  from evals.record import record_sampling
  from evals.registry import Registry
label_desc: Use image node_id 1 to create a new RetrievalCompletionFn object from inherited base classes: CompletionFn with example: obj = RetrievalCompletionFn(completion_fn, embeddings_and_text_path, retrieval_template, k, embedding_model, registry, registry_path)