Code Monkey home page Code Monkey logo

database-query-extension's Introduction

Database Query Extension

Note: This project is experimental and is not an officially supported Google product.

Introduction

This project is intended to be a working demo showcasing how to extend an LLM-based application using Cloud Databases for Retrieval Augmented Generation (RAG). It's intended to both demonstrate how to best use advanced RAG patterns with Databases, as well as provide a basic outline for extending your own LLMs.

This demo showcases an "SFO Airport Assistant": a San Francisco Airport-based AI assistant that has access to information about airports, flights, and amenities. It can help answer users questions like:

  • Are there any luxury shops?
  • Where can I get coffee near gate A6?
  • Where can I find a gift?
  • What flights are headed to NYC tomorrow?

Table of Contents

Architecture

Overview

Overview

This demo contains 3 key parts:

  1. Application -- The LLM-based app that acts as orchestrates layer for the interaction with the LLM.
  2. Extension -- The extension service provides the application concrete, discrete actions that allow the LLM to interact with the Database.
  3. Database -- The database containing the data the LLM can use to answer questions. For this application, the database used was intentionally designed to be interchangeable in order to make it easier to run this on your preferred database.

Extension as a service

While it's often possible to expose similar functionality directly into your application, running your extension service has several benefits:

  1. Better recall - LLMs perform better when given smaller, discrete tasks they can use to accomplish larger goals. By mapping a specific action to a specify, pre-determined query it significantly improves the LLMs ability to leverage it successfully.
  2. Better scalability - Running the extension as a separate service both allows multiple different LLMs to leverage it, as well as allowing it to scale independently. It allows allows production best practices such as connection pooling or caching.
  3. Better security - LLMs are susceptible to attacks such as "jailbreaking" to circumvent safety measures that are put in place. Using an intermediary service allows the application to handle authentication and authorization through more standard and secure channels.

Deploying

Deploying this demo consists of 3 steps:

  1. Setting up your Database -- creating your database and initializing it with data
  2. Deploying your Extension -- deploying your extension service and connecting it to your database
  3. Running the LLM-based application -- running your application locally

Setting up your Database

The extension service uses an interchangeable 'datastore' interface. Choose one of any of the database's listed below to set up and initialize your database:

Deploying the Extension Service

Instructions for deploying the extension service

Running the LLM-based Application

Instructions for running app locally

Writing your own extension

This demo can also serve as a starting point for writing your own extension. The directory is organized into the following folders:

Directory Description
data Contains CSV files with the dataset for a working demo.
extension-service Contains the service for extending an LLM with information from the database.
langchain_tools_demo Contains an LLM-based application that that uses the extension service via LangChain.

You can copy or fork the extension-service folder to customize it to your needs. There are two main places you want to start:

  • extension-service/app/routes.py - contains the API endpoints that the LLM will call
  • extension-service/datastore/datastore.py - contains the interface used to abstract the database. There are specific implementations of this in the providers folder that can be customized with logic for your specific schema.

database-query-extension's People

Contributors

yuan325 avatar averikitsch avatar duwenxin99 avatar andrewbrook-google avatar kurtisvg avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.