Pre-built Agents
RAG Powered Agents
search_agent
Usage
Quick Start

B. Usage

a) Quick Start

Before diving into the SearchAgent SDK, it's essential to confirm that your environment includes all required dependencies. Although exact installation commands aren't outlined here, you can utilize standard Python package management tools such as pip to handle your environment setup.

Key Components

The SDK consists of several essential components, each designed to manage various types of content:

  • PDF Files
  • DOCX Files
  • Text Files
  • Webpages
  • Websites
  • YouTube Videos

These components enable the SearchAgent to train, process, and index content from these sources, rendering it searchable within your Search Agent.

Using the SearchAgent SDK

The following sections provide a step-by-step guide to using the SearchAgent SDK in your projects.

Initializing the SearchAgent

To use the SDK, start by importing and initializing the SearchAgent class:

from <<package name>> import SearchAgent 
 
# Initialize the SearchAgent
search_agent = SearchAgent()

Setup Vector Database

First install Qdrant Vector Database with pip install qdrant_client

import qdrant_client
 
QDRANT_CLIENT_URL = "<YOUR-QDRANT-CLIENT-URL>"
QDRANT_API_KEY = "<YOUR-QDRANT-API-KEY>"
 
client = qdrant_client.QdrantClient(
    url=QDRANT_CLIENT_URL,
    api_key=QDRANT_CLIENT_URL,
)
 
vector_store_params = {
    "vector_store_type": "QdrantVectorStore",
    "client": client,
    "collection_name": "some_name"
}

Search Agent supports a variety of Vector Databases

Setup Large Language Model

import os
import openai
 
os.environ["OPENAI_API_KEY"] = "<YOUR-OPENAI-API-KEY>"
 
llm_params = {
    "model": "gpt-4-turbo-preview",
    "api_key": "<YOUR-OPENAI-API-KEY>"
}

Search Agent supports a variety of Large Language Models

Training Search Agent

With the SearchAgent initialized, you can begin adding content from various sources. The SDK provides methods for integrating different content types, as outlined below.

Adding PDF Files

search_agent.add_pdf(
    input_files=["path-to-file"],
    vector_store_params=vector_store_params,
    llm_params=llm_params
)

Adding DOCX Files

search_agent.add_docx(
    input_files=["path-to-file"],
    vector_store_params=vector_store_params,
    llm_params=llm_params
)

Adding Text Files

search_agent.add_text(
    input_files=["path-to-file"],
    vector_store_params=vector_store_params,
    llm_params=llm_params
)

Adding Webpages

search_agent.add_webpage(
    url="https://example.com",
    vector_store_params=vector_store_params,
    llm_params=llm_params
)

Adding Websites

search_agent.add_website(
    url="https://sample.com",
    vector_store_params=vector_store_params,
    llm_params=llm_params
)

Example Usage

Adding Text Files from a Directory

This snippet configures the chat agent to ingest text files from the specified directory and its subdirectories.

chat_agent.txt_chat(
    input_dir="/path/to/your_text/files",
    recursive=True
)

Let’s Search

Ask a question

response = agent.query("<you-question>")

Sources

for n, source in enumerate(response.source_nodes):
  print(source.text)
  print(source.score)
  print(source.metadata)

Advanced Configuration

Each method provides a variety of parameters, allowing for precise customization of content processing and indexing. These parameters include options for handling hidden files, controlling recursive directory processing, and specifying file extensions.