Here is a README file for your repository.
This project is a minimal, self-contained implementation of a Retrieval-Augmented Generation (RAG) pipeline using Python. It queries embeddings stored in a Cloud SQL database (populated by a separate ingestion script) and uses Google Vertex AI's Gemini models to answer questions based on those documents.
It's designed to be a straightforward example of how to build a powerful Q&A bot over your own documentation without needing complex cloud infrastructure.
The runtime pipeline performs the following steps:
- Embed Query: Your question is embedded into a vector using the Vertex AI text embedding model.
- Search Cloud SQL: The query embedding is compared against vectors stored in the
docs_opennebula_iotable of Cloud SQL usingpgvectorto retrieve the most relevant text chunks. - Generate: The retrieved chunks and your question are sent to the Gemini model on Vertex AI to produce a context-aware answer.
For larger scale ingestion into Google Cloud SQL, see ingest_opennebula_docs.py, which crawls the entire OpenNebula 7.0 documentation, embeds the text with Vertex AI, and stores the results in a Cloud SQL table.
Follow these steps to get the project running.
-
Prerequisites:
- Python 3.8 or newer
- A Google Cloud project with Vertex AI enabled and application default credentials configured.
-
Clone the Repository:
git clone <your-repo-url> cd <your-repo-directory>
-
Install Dependencies:
pip install -r requirements.txt
(Note: If you don't have a
requirements.txtfile, create one with the contents from thepip installcommand in the script, or just run the command directly). -
Configure Project Info:
* Create a file named `.env` in the root directory of the project. * Add your Vertex AI project configuration: ``` GCP_PROJECT_ID="your-project-id" GCP_REGION="us-central1" ```
Running the Q&A pipeline is simple.
-
Customize the Script (Optional): Open the
rag_pipeline.pyfile and modify theUSER_QUERYvariable at the bottom to ask your own question:USER_QUERY = "What is the main topic of this documentation?"
-
Run the Script: Execute the script from your terminal:
python rag_pipeline.py
The script will then perform the entire RAG process and print the final question and its generated answer to the console.
-
Run the tests (optional):
pytest
These tests rely on a dummy embedding model and require no cloud access.
-
Manual verification with your project:
- Ensure a
.envfile withGCP_PROJECT_ID,GCP_REGION, and Cloud SQL credentials exists. - Adjust
USER_QUERYif desired. - Run
python rag_pipeline.pyand review the generated answer.
- Ensure a
-
Ingest OpenNebula docs into Cloud SQL (optional):
- Provision a Cloud SQL PostgreSQL instance and note the connection name, database, user, and password.
- Add these values to your
.env:CLOUD_SQL_CONNECTION_NAME="project:region:instance" DB_USER="username" DB_PASS="password" DB_NAME="database" APPEND_REFERENCES="false" # set to "true" to include reference links in answers - Run the ingestion script:
This script crawls all pages under
python ingest_opennebula_docs.py
https://docs.opennebula.io/7.0/, splits the content into chunks, embeds them with Vertex AI, and stores the embeddings in thedocs_opennebula_iotable inside your Cloud SQL database.
- Language: Python
- LLM & Embeddings: Vertex AI Gemini (
gemini-pro,text-embedding-004)- Core Libraries:
langchain: For text splitting.pgvector+sqlalchemy: For similarity search in Cloud SQL.beautifulsoup4: For parsing HTML.requests: For making HTTP requests.
- Core Libraries:
This project is licensed under the MIT License. See the LICENSE file for details.