{"id":14064886,"url":"https://github.com/mazzasaverio/fastapi-langchain-rag","last_synced_at":"2025-04-11T17:20:38.879Z","repository":{"id":230194918,"uuid":"778222591","full_name":"mazzasaverio/fastapi-langchain-rag","owner":"mazzasaverio","description":"(Let's start with a) Scalable question-answering system utilizing FastAPI, LangChain (LCEL), and PGVector, featuring an ingestion pipeline. Deployed on GCP Cloud Run via Terraform.","archived":false,"fork":false,"pushed_at":"2024-04-10T11:18:45.000Z","size":235,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-10T18:27:20.872Z","etag":null,"topics":["chatbot","cloud-run","fastapi","langchain","pgvector","question-answering","rag"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mazzasaverio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-27T10:10:30.000Z","updated_at":"2024-04-14T22:33:02.978Z","dependencies_parsed_at":"2024-04-14T22:32:53.223Z","dependency_job_id":null,"html_url":"https://github.com/mazzasaverio/fastapi-langchain-rag","commit_stats":null,"previous_names":["mazzasaverio/fastapi-ai-agent","mazzasaverio/fastapi-langchain-rag"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Ffastapi-langchain-rag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Ffastapi-langchain-rag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Ffastapi-langchain-rag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mazzasaverio%2Ffastapi-langchain-rag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mazzasaverio","download_url":"https://codeload.github.com/mazzasaverio/fastapi-langchain-rag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248447609,"owners_count":21105140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","cloud-run","fastapi","langchain","pgvector","question-answering","rag"],"created_at":"2024-08-13T07:04:09.352Z","updated_at":"2025-04-11T17:20:38.850Z","avatar_url":"https://github.com/mazzasaverio.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Project Overview\n\nThe goal of developing this repository is to create a scalable project based on RAG operations of a vector database (Postgres with pgvector), and to expose a question-answering system developed with LangChain and FastAPI on a Next.js frontend.\n\nThe entire system will be deployed in a serverless manner, both on the backend (a Terraform submodule for setting up a cloud run with CloudSQL and Redis) and on the frontend (deployment via Vercel).\n\nAdditionally, a layer will be added to limit the app's usage through a subscription plan via Stripe\n\n## Setting Up the Infrastructure\n\n### Import Terraform Submodule\n\nRefer to the following guide for adding and managing submodules:\n[Adding a Submodule and Committing Changes: Git, Terraform, FastAPI](https://medium.com/@saverio3107/adding-a-submodule-and-committing-changes-git-terraform-fastapi-6fe9cf7c9ba7?sk=595dafdaa36427a2d6efee8c08940ee9)\n\n**Steps to Initialize Terraform:**\n\nNavigate to the Terraform directory and initialize the configuration:\n\n```bash\ncd terraform\nterraform init\nterraform apply\n```\n\n## Configuring the Application\n\n### Set Environment Variables\n\nDuplicate the `.env.example` file and set the required variables:\n\n```bash\ncp .env.example .env\n```\n\n### Backend Setup\n\n- **Navigate to the backend directory:**\n\n```bash\ncd backend\n```\n\n- **Install dependencies using Poetry:**\n\n```bash\npoetry install\npoetry shell\n```\n\n### Database Connection\n\nConnect to the database using the Cloud SQL Proxy. Instructions are available in the Terraform README.\n\n```bash\n./cloud-sql-proxy ...\n```\n\n### Initialize Database\n\nRun the initialization script to set up the database. This script adds the pgvector extension and creates a superuser:\n\n```bash\npython app/init_db.py\n```\n\n### Data Ingestion\n\nPlace your PDF files in `data/raw` and run the following script to populate the database:\n\n```bash\npython app/ingestion/run.py\n```\n\n## Accessing the Application\n\n### API Documentation\n\nAccess live-generated API documentation at:\n\n```\nhttps://cloudrun-service-upr23soxia-uc.a.run.app/api/v1/docs\n```\n\n### Obtaining an Access Token\n\nGenerate an access token using the `/api/v1/login/access-token` endpoint with credentials specified in your `.env` file.\n\n## Connecting the Frontend\n\n### Generate an Access Token\n\nObtain an access token using the login endpoint:\n\n```javascript\nconst token = \"your_generated_access_token_here\"; // Replace with actual token\n```\n\n### Example Frontend Integration\n\nUtilize the access token in your Next.js application as follows:\n\n```javascript\nconst headers = new Headers({\n  Authorization: \"Bearer \" + token,\n  \"Content-Type\": \"application/json\",\n});\n\nasync function chatAnswer() {\n  const res = await fetch(\n    `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/qa/chat`,\n    {\n      method: \"POST\",\n      headers: headers,\n      body: JSON.stringify({ message: \"Your query here\" }),\n    }\n  );\n  return res.json();\n}\n```\n\n## Subscription Management\n\nIntegrate Stripe to manage subscriptions and limit usage based on the chosen plan. Follow Stripe's official documentation to set up the billing and subscription logic.\n\n## Contributing\n\nContributions are welcome! For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazzasaverio%2Ffastapi-langchain-rag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmazzasaverio%2Ffastapi-langchain-rag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmazzasaverio%2Ffastapi-langchain-rag/lists"}