This project sets up an AI chat agent that can answer questions based on documents stored in a Google Drive folder. It uses a vector database (ChromaDB) to store document embeddings and an AI model (via Ollama) to understand questions and generate answers.
- Google Drive Integration: Automatically downloads and processes documents (Word, PDF, Google Docs) from a specified Google Drive folder.
- Document Embedding: Converts document content into numerical representations (embeddings) for efficient searching.
- Vector Database: Stores and retrieves document embeddings using ChromaDB.
- AI Chat Agent: Answers user questions by finding relevant information in the processed documents.
Before you can run this project, you need to have a few things installed on your computer:
-
Node.js: This is a JavaScript runtime that allows you to run the project's code.
- How to check if you have it: Open your computer's terminal or command prompt and type
node -v. If you see a version number (e.g.,v18.x.xor higher), you're good to go. - How to install: If you don't have Node.js, visit the official Node.js website (https://nodejs.org/) and download the recommended version for your operating system. Follow the installation instructions.
- How to check if you have it: Open your computer's terminal or command prompt and type
-
Docker: This is used to run ChromaDB, our vector database, in a separate, isolated environment.
- How to check if you have it: Open your terminal or command prompt and type
docker --version. If you see a version number, you're all set. - How to install: Visit the Docker Desktop website (https://www.docker.com/products/docker-desktop) and download the installer for your operating system. Follow the installation instructions.
- How to check if you have it: Open your terminal or command prompt and type
-
Ollama: This is a tool that allows you to run large language models (LLMs) locally on your computer. We use it for generating document embeddings.
- How to check if you have it: Open your terminal or command prompt and type
ollama --version. If you see a version number, you're good. - How to install: Visit the Ollama website (https://ollama.com/) and download the installer for your operating system. Follow the installation instructions.
- Download the embedding model: Once Ollama is installed, open your terminal and run:
This will download the necessary embedding model.
ollama pull nomic-embed-text
- How to check if you have it: Open your terminal or command prompt and type
-
Google Cloud Credentials: To access your Google Drive, you need to set up a Google Cloud project and enable the Google Drive API.
- Create a Service Account: Follow Google's instructions to create a service account and download its JSON key file.
- Rename and Place the Key File: Rename the downloaded JSON file to
ai-agent-google-credentials.jsonand place it in the root directory of this project (the same folder asindex.js). - Enable Google Drive API: Make sure the Google Drive API is enabled for your Google Cloud project.
-
Clone the Repository: If you haven't already, download or clone this project to your computer. You can do this by opening your terminal or command prompt, navigating to where you want to save the project, and typing:
git clone <repository_url> cd groq-policy-agent
(Replace
<repository_url>with the actual URL of this repository.) -
Install Project Dependencies: Navigate to the project's folder in your terminal (if you're not already there) and install the required libraries:
npm install
-
Start ChromaDB: Open your terminal and run the following command to start the ChromaDB server using Docker. This will run ChromaDB in the background.
docker run -p 8000:8000 chromadb/chroma
You should see output indicating that ChromaDB is listening on port 8000. Keep this terminal window open, or run it in a detached mode if you know how (
docker run -d -p 8000:8000 chromadb/chroma). -
Verify Ollama Model: Ensure that Ollama is running and you have pulled the
nomic-embed-textmodel as described in the "Prerequisites" section. -
Configure Google Drive Folder ID: Create or open a file named
config.txtin the root directory of the project. Add the following line to it, replacingyour_google_drive_folder_idwith the actual ID of your Google Drive folder containing the policy documents. You can find the folder ID in the URL when you open the folder in Google Drive (it's the long string of characters after/folders/).GOOGLE_FOLDER_ID=your_google_drive_folder_id -
Configure AI System Message: Open the
system_message.txtfile in the root directory of the project. You can edit the content of this file to change the initial instructions or persona of the AI agent. For example:You are a friendly and helpful customer support agent.This message will be used as the system prompt for the AI model.
Once all the setup steps are complete, you can start the AI agent:
-
Open your terminal and navigate to the project's root directory (
groq-policy-agent). -
Run the main script:
node index.js
-
Interact with the Chat: The script will first download and process your documents. Once it's ready, you'll see a prompt like:
--- Chat with the AI Agent --- Type 'exit' or 'quit' to end the chat. You:Type your questions after
You:and press Enter. The AI agent will respond based on the documents it processed. -
To Exit: Type
exitorquitand press Enter to end the chat session.
Error: Request to Ollama server failed: 404 Not Found:- Solution: Ensure Ollama is running and you have successfully run
ollama pull nomic-embed-text.
- Solution: Ensure Ollama is running and you have successfully run
ChromaClientError: Bad request... Collection expecting embedding with dimension of XXX, got YYY:- Solution: This usually means the ChromaDB collection was created with a different embedding size. The script is designed to delete and recreate the collection on each run, which should fix this. If it persists, ensure your Docker container for ChromaDB is running correctly.
ENOENT: no such file or directory, open './test/data/...':- Solution: This error was related to an internal dependency. It should be resolved with the current setup. If it reappears, ensure you have run
npm installafter any changes topackage.json.
- Solution: This error was related to an internal dependency. It should be resolved with the current setup. If it reappears, ensure you have run
SyntaxErrororReferenceError:- Solution: These are usually coding errors. Ensure you haven't accidentally modified the JavaScript files in a way that breaks their syntax. Re-cloning the repository and following the setup steps carefully might help.
- Google Drive Authentication Issues:
- Solution: Double-check that your
ai-agent-google-credentials.jsonfile is correctly named and placed in the project root, and that the Google Drive API is enabled in your Google Cloud project.
- Solution: Double-check that your
If you encounter any other issues, please describe them in detail, and I'll do my best to help!