Skip to main content

Generated from aind-library-template

Project description

GAMER: Generative Analysis for Metadata Retrieval

License Code Style semantic-release: angular Interrogate Coverage Python

Installation

Install a virtual environment with python 3.11 (install a version of python 3.11 that's compatible with your operating system).

py -3.11 -m venv .venv

On Windows, activate the environment with

.venv\Scripts\Activate.ps1

You will need access to the AWS Bedrock service in order to access the model. Once you've configured the AWS CLI, and granted access to Anthropic's Claude Sonnet 3 and 3.5, proceed to the following steps.

Install the chatbot package -- ensure virtual environment is running.

pip install metadata-chatbot

Usage

To call the model,

from metadata_chatbot.agents.GAMER import GAMER

query = "What was the refractive index of the chamber immersion medium used in this experiment SmartSPIM_675387_2023-05-23_23-05-56"
model = GAMER()
result = model.invoke(query)

print(result)

To call the model asynchronously, which reduces the model's call time by ~50%, run --

result = await model.ainvoke(query)
print(result)

High Level Overview

The project's main goal is to developing a chat bot that is able to ingest, analyze and query metadata. Metadata is accumulated in lieu with experiments and consists of information about the data description, subject, equipment and session. To maintain reproducibility standards, it is important for metadata to be documented well. GAMER is designed to streamline the querying process for neuroscientists and other users.

Model Overview

The current chat bot model uses Anthropic's Claude Sonnet 3 and 3.5, hosted on AWS' Bedrock service. Since the primary goal is to use natural language to query the database, the user will provide queries about the metadata specifically. The framework is hosted on Langchain. Claude's system prompt has been configured to understand the metadata schema format and craft MongoDB queries based on the prompt. Given a natural language query about the metadata, the model will produce a MongoDB query, thought reasoning and answer. This method of answering follows chain of thought reasoning, where a complex task is broken up into manageable chunks, allowing logical thinking through of a problem.

The main framework used by the model is Retrieval Augmented Generation (RAG), a process in which the model consults an external database to generate information for the user's query. This process doesn't interfere with the model's training process, but rather allows the model to successfully query unseen data with few shot learning (examples of queries and answers) and tools (e.g. API access) to examine these databases.

Multi-Agent graph framework

A multi-agent workflow is created using Langgraph, allowing for parallel execution of tasks, like document retrieval from the vector index, and increased developer control over the the RAG process. Decision nodes and their roles are further explained in the GAMER_workbook.

Worfklow

Data Retrieval

Vector Embeddings

To improve retrieval accuracy and decrease hallucinations, we use vector embeddings to access relevant chunks of information found across the database. This process starts with accessing assets, and chunking each json file to chunks of around 8000 tokens (10 chunks per file)-- each chunk preserves the hierarchy found in json files. These chunks are converted to vector arrays of size 1024, through an embedding model (Amazon's Titan 2.0 Embedding). The user's query is converted to a vector and projected onto the latent space. The chunks that contain the most relevant information will be accessed through a cosine similarity search.

AIND-data-schema-access REST API

For queries that require accessing the entire database, like count based questions, information is accessed through an aggregation pipeline, provided by one of the constructed LLM agents, and the API connection.

Current specifications

  • The model can query the fields for a specified asset.
  • The model can query metadata documents from the document database.
  • The model is able to return a list of unique values for a given field.
  • The model is able to answer count based questions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metadata_chatbot-0.0.70.tar.gz (112.0 kB view details)

Uploaded Source

Built Distribution

metadata_chatbot-0.0.70-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file metadata_chatbot-0.0.70.tar.gz.

File metadata

  • Download URL: metadata_chatbot-0.0.70.tar.gz
  • Upload date:
  • Size: 112.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for metadata_chatbot-0.0.70.tar.gz
Algorithm Hash digest
SHA256 71641d10cdbed9a84deafeb5f1a5f0ef16f611f0650a28feae7ac1d0983de5b1
MD5 e757816aa6fd03dfae8495d776d2ff2f
BLAKE2b-256 0adbeb0848750bd148c42d82bca311b0127ea4a7737745342f04d4120cf12937

See more details on using hashes here.

File details

Details for the file metadata_chatbot-0.0.70-py3-none-any.whl.

File metadata

File hashes

Hashes for metadata_chatbot-0.0.70-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0dc14341a001b515c6b7ee43c24b0dd064dbe20a32827affe1207544a15c21
MD5 66c2c2f15d241124c9e0622dda1c0c72
BLAKE2b-256 68f20fbc532d933feba35c694ad1faf2c310b82e64fb54dcdce07759e4e37b2a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page