Skip to content

Commit

Permalink
doc: added high-level explainations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisVLRT committed Feb 8, 2024
1 parent cff24fb commit bad8eb6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
16 changes: 16 additions & 0 deletions backend/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
load_dotenv()
POOL = None
class Database:
"""
Handles database operations.
It manages the connection pool, executes queries, and handles transactions.
The class uses a context manager to ensure that database connections are properly
opened and closed. It supports SQLite, PostgreSQL, and MySQL databases.
Attributes:
connection_string (str): The database connection string.
logger (Logger): The logger instance for logging messages.
url (URL): The parsed URL object of the connection string.
pool (PooledDB): The connection pool for database connections.
conn (Connection): The current database connection.
DIALECT_PLACEHOLDERS (dict): Mapping of database dialects to their placeholder symbols.
"""

DIALECT_PLACEHOLDERS = {
"sqlite": "?",
"postgresql": "%s",
Expand Down
21 changes: 13 additions & 8 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
from fastapi import FastAPI
from langserve import add_routes

from backend.api_plugins import (
authentication_routes,
)
from backend.database import Database
from backend.rag_components.rag import RAG


# Initialize the SQL database backing the application
# TODO: documentation link
with Database() as connection:
connection.initialize_schema()

# Initialize a RAG as discribed in the config.yaml file
# https://artefactory.github.io/skaff-rag-accelerator/rag_object/
rag = RAG(config=Path(__file__).parent / "config.yaml")
chain = rag.get_chain(memory=True)
chain.get_graph().print_ascii()
chain = rag.get_chain()

app = FastAPI()
auth = authentication_routes(app)

# Create a minimal RAG server based on langserve
# Learn how to extend this configuration to add authentication and session management
# https://artefactory.github.io/skaff-rag-accelerator/api_plugins/
app = FastAPI(
title="RAG Accelerator",
description="A RAG-based question answering API",
)
add_routes(
app,
chain,
dependencies=[auth],
)

0 comments on commit bad8eb6

Please sign in to comment.