Skip to content

vinaypoddar/ai-document-assistant-agent

Repository files navigation

ai-document-assistant-agent

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.

Features

  • 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.

Prerequisites

Before you can run this project, you need to have a few things installed on your computer:

  1. 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.x or 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.
  2. 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.
  3. 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:
      ollama pull nomic-embed-text
      This will download the necessary embedding model.
  4. 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.json and place it in the root directory of this project (the same folder as index.js).
    • Enable Google Drive API: Make sure the Google Drive API is enabled for your Google Cloud project.

Setup Steps

  1. 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.)

  2. 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
  3. 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).

  4. Verify Ollama Model: Ensure that Ollama is running and you have pulled the nomic-embed-text model as described in the "Prerequisites" section.

  5. Configure Google Drive Folder ID: Create or open a file named config.txt in the root directory of the project. Add the following line to it, replacing your_google_drive_folder_id with 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
    
  6. Configure AI System Message: Open the system_message.txt file 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.

How to Run the AI Agent

Once all the setup steps are complete, you can start the AI agent:

  1. Open your terminal and navigate to the project's root directory (groq-policy-agent).

  2. Run the main script:

    node index.js
  3. 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.

  4. To Exit: Type exit or quit and press Enter to end the chat session.

Troubleshooting / Common Issues

  • Error: Request to Ollama server failed: 404 Not Found:
    • Solution: Ensure Ollama is running and you have successfully run ollama pull nomic-embed-text.
  • 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 install after any changes to package.json.
  • SyntaxError or ReferenceError:
    • 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.json file is correctly named and placed in the project root, and that the Google Drive API is enabled in your Google Cloud project.

If you encounter any other issues, please describe them in detail, and I'll do my best to help!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors