1. Search Flow Overview:
The application takes a user's query, fetches relevant web pages from Google Search, extracts text content from these pages, and then uses this extracted content as context for generating an answer using OpenAI's chat completion API. The application focuses on providing concise answers with citations linked back to the source web pages.
2. Key Search Components:
- Search execution pattern: The application uses server-side logic to perform the Google Search scraping and subsequently calls the OpenAI API. This is a synchronous process where the user waits for the entire search and answer generation to complete.
- Query construction approach: The query is taken directly from user input and used as-is for the Google Search. No explicit query refinement or expansion is performed.
- Result processing mechanism: The top links from the Google Search results are fetched, and the content of these pages is extracted using the Readability library. This extracted text is cleaned and truncated before being used in the prompt for the LLM.
- Context management method: Context is managed per search. Each search starts fresh; no information is carried over from previous searches. The context for a given search consists solely of the text extracted from the top Google Search results for that specific query.
3. Search Implementation Steps:
- Query formation: The user's input is directly used as the search query.
- Search execution: A
fetch call is made to Google Search using the user's query. The HTML is parsed using Cheerio to extract URLs from the search results.
- Result processing: The top URLs are fetched, and their content is extracted using Readability. The extracted text is cleaned and truncated.
- Context integration: The cleaned and truncated text from multiple sources is combined into a single prompt for the OpenAI API, clearly delineating each source with a numerical identifier.
4. Notable Search Features:
- Query refinement techniques: None implemented.
- Result filtering methods: Basic filtering is done to remove links from major social media and Google-owned sites. Duplicate domains are also filtered out.
- Context preservation strategies: No context is preserved between searches.
- Search iteration patterns: No iterative search refinement is performed. The initial search results are final.
5. Search-Specific Dependencies:
- cheerio: Used for parsing the HTML of the Google Search results page.
- @mozilla/readability: Used for extracting clean text content from web pages.
- jsdom: Provides a DOM environment for Readability to function.
It is important to note that the current implementation relies on scraping Google Search results, which is fragile and can be easily broken by changes to Google's HTML structure. A more robust solution would use the official Google Search API. Also, the current system does not implement any query processing, result ranking, or context management across searches, which limits its sophistication compared to more advanced LLM-powered search agents.