Services Overview
Services Overview
A)Retriever service:
This service essentially acts as a document retrieval and question-
answering system that:
1. Takes a user query
2. Searches through indexed documents in Pinecone
3. Uses GPT-4 to generate answers based on relevant document
chunks
4. Returns structured results with source information
components and functionality:
1. Imports and Dependencies (key libraries used):
pinecone: For vector database operations
Langchain: For working with LLMs and document processing
FastAPI: For creating the web API
pandas: For data manipulation
2. Main Components:
a) Helper Function:
def extract_unique_sources(query_result):
This function extracts unique document IDs from Pinecone query
results
It processes the matches from the query result and collects
unique document IDs
b) API Setup:
Uses FastAPI framework
Creates a router with prefix "/api/v1"
Has two endpoints:
/api/v1/steps/retriever (POST)
/api/v1/health (GET)
3. Main Retriever Endpoint (/api/v1/steps/retriever):
This is the core functionality that:
Accepts POST requests with JSON data containing:
query: The user's question
restrictToDocumentIds: list of specific documents to search
documentType: Type of document to filter
documentcategory: Category of document to filter
4. Configuration:
Uses environment variables for various credentials:
OpenAI/Azure credentials (API base, key, version, type)
Pinecone credentials (API key, environment, index name)
5. Core Processing Flow:
a) Setup:
Initializes Azure OpenAI LLM (GPT-4)
Sets up OpenAI embeddings (using Ada model)
Initializes Pinecone connection
b) Document Retrieval:
Queries Pinecone index with filters based on:
Document type
Document category
Specific document IDs
Retrieves up to 1000 matches (configurable)
c) Processing:
For each unique document:
Creates a RetrievalQA chain
Processes the user's query
Stores results in a pandas DataFrame with columns:
o documentId
o documentCategory
o documentType
o fileName
o result
6. Output:
Returns JSON response containing:
results: List of processed documents and their answers
errors: Any internal errors that occurred
7. Error Handling:
Includes basic error handling for value errors
Returns appropriate HTTP status codes (200 for success, 400 for
errors)
B)Vectorization service:
Responsible for processing documents and converting them into
vector embeddings for efficient retrieval.
The main business purpose of this service is to:
1. Take HTML documents
2. Process them into searchable chunks
3. Convert these chunks into vector embeddings
4. Store them in a vector database for efficient semantic search