Skip to main content

FinancialSituationMemory

This class manages a vector store for financial situations and their corresponding advice, leveraging OpenAI for embeddings and AWS S3 for storage. It ensures the necessary S3 bucket and vector index are created and configured upon initialization. The class provides methods to add new situation-advice pairs and retrieve the most similar past situations based on a given current situation, returning associated recommendations and similarity scores.

Attributes

  • name: str = None

    • The name of the financial situation memory.
  • embedding_model: str = None

    • The embedding model to use for generating embeddings.
  • dimension: int = None

    • The dimension of the embeddings.
  • region_name: str = None

    • The AWS region name for the S3 bucket.
  • bucket_name: str = None

    • The name of the S3 bucket to store vectors.
  • index_name: str = f"trading-agents-{name}"

    • The name of the vector index.
  • openai_client: OpenAI = OpenAI()

    • The OpenAI client for generating embeddings.
  • client: boto3.client = boto3.client("s3vectors", region_name=region_name)

    • The boto3 client for S3 vectors.

Constructors

  • Initializes the FinancialSituationMemory with necessary parameters for storing and retrieving financial situations.

  • Parameters

    • name: string
      • A unique name for the financial situation memory.
    • embedding_model: string
      • The name of the embedding model to use for generating vector embeddings.
    • dimension: int
      • The dimension of the vector embeddings.
    • region_name: string
      • The AWS region name where the S3 bucket is located.
    • bucket_name: string
      • The name of the S3 bucket to use for storing vectors.

Methods

def get_embedding(text: string) - > list[float]
  • Get OpenAI embedding for a given text

  • Parameters

    • text: string
      • The input text to generate an embedding for.
  • Return Value: list[float]

    • A list of floats representing the embedding vector.
def add_situations(situations_and_advice: list[tuple[str, str]])
  • Store situation + recommendation pairs in the vector store.

  • Parameters

    • situations_and_advice: list[tuple[str, str]]
      • A list of tuples, where each tuple contains a situation string and a recommendation string.
def get_memories(current_situation: string, n_matches: int = 1) - > list[dict]
  • Retrieve the top-n most similar situations from memory

  • Parameters

    • current_situation: string
      • The current situation to query for similar memories.
    • n_matches: int
      • The number of top similar situations to retrieve.
  • Return Value: list[dict]

    • A list of dictionaries, each containing the matched situation, recommendation, and similarity score.