|
| 1 | +# Search Graph |
| 2 | + |
| 3 | +This module implements a state-based graph for performing web searches, extracting key information, and generating responses based on user queries. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Key Components |
| 8 | + |
| 9 | +1. **SearchState**: Defines the structure for storing search-related information. |
| 10 | + |
| 11 | +2. **StateGraph**: Utilizes LangChain's StateGraph to manage the flow of operations. |
| 12 | + |
| 13 | +3. **Main Nodes**: |
| 14 | + |
| 15 | + - `performSearchNode`: Executes the web search using the Tavily API. |
| 16 | + - `extractKeyPointsNode`: Identifies and extracts key points from search results. |
| 17 | + - `generateRelatedQueriesNode`: Creates related queries based on the initial search. |
| 18 | + - `generateResponseNode`: Produces a final response and report based on all gathered information. |
| 19 | + |
| 20 | +4. **Utility Functions**: |
| 21 | + |
| 22 | + - `filterSearchResults`: Filters search results based on a minimum score. |
| 23 | + - `formatSearchResults`: Formats the search results for further processing. |
| 24 | + |
| 25 | +5. **LLM Integration**: Utilizes GPT models for various natural language processing tasks. |
| 26 | + |
| 27 | +## Workflow |
| 28 | + |
| 29 | +1. The search process begins with a user query. |
| 30 | +2. The query is used to perform a web search. |
| 31 | +3. Key points are extracted from the search results. |
| 32 | +4. Related queries are generated to expand the search scope. |
| 33 | +5. A final response and report are generated based on all collected information. |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +The module exports two main functions: |
| 38 | + |
| 39 | +1. `performSearch`: Executes the entire search process and returns the final state. |
| 40 | +2. `streamSearchProcess`: Provides a stream of intermediate states during the search process. |
| 41 | + |
| 42 | +## Example Usage |
| 43 | + |
| 44 | +```ts |
| 45 | +const result = await performSearch( |
| 46 | + "How do I register to vote in Oregon?", |
| 47 | + config |
| 48 | +); |
| 49 | +``` |
| 50 | + |
| 51 | +## Example Response |
| 52 | + |
| 53 | +```json |
| 54 | +{ |
| 55 | + "query": "how do I register to vote in Oregon?", |
| 56 | + "searchResults": [ |
| 57 | + "State of Oregon: Elections - Voting in Oregon\n\nRegistering to vote in Oregon is quick and simple. Oregonians can register: Online using My Vote. By mail using a voter registration form.This form also is available in multiple languages . In person at the county elections office or at certain state agencies like the DMV. The deadline to register is 21 days before Election Day.[1]", |
| 58 | + "Register to Vote Online in Oregon - Vote.org\n\nOregon. voter registration rulesTo register in Oregon you must: Be a citizen of the United States; Be a resident of Oregon; At least 16 years old (to vote, you must be 18 by Election Day). Oregon. voter registration directionsUse our Register to Vote Tool to fill out the National Voter Registration Form.[2]", |
| 59 | + "State of Oregon: Voting - Update Voter Registration Information\n\nElectronically. If you have an Oregon driver license or state ID card, you can update your information entirely online. Go To My Vote. Enter your name and date of birth. Click Submit. Select Update Registration at the bottom of the page. Answer the two eligibility questions on the next screen. Click Continue.[3]", |
| 60 | + "How to register in Oregon | Vote.gov\n\nStart or update your registration on Oregon's election website. You can also register to vote by mail or in person on Oregon's election website. Voter registration deadlines. Voter registration deadlines for the Tuesday, November 5, 2024 election. Find state and local election dates. Online registration deadline: Tuesday, October 15, 2024[4]", |
| 61 | + "Voter Registration Information - State of Oregon: Voting & Elections\n\nIf you do not have a valid Oregon ID or Social Security number you can find a list of acceptable alternative identification online at oregonvotes.gov. What is the deadline to register? To vote in the May 21, 2024, Primary Election, your completed registration card must be: postmarked by Tuesday, April 30; or; delivered to a county elections ...[5]" |
| 62 | + ], |
| 63 | + "sources": [ |
| 64 | + "https://sos.oregon.gov/voting/Pages/voteinor.aspx", |
| 65 | + "https://www.vote.org/register-to-vote/oregon/", |
| 66 | + "https://sos.oregon.gov/voting/Pages/updatevoterregistration.aspx", |
| 67 | + "https://vote.gov/register/oregon", |
| 68 | + "https://oregonvotes.gov/voters-guide/english/geninfo_voterreginfo.html" |
| 69 | + ], |
| 70 | + "keyPoints": [ |
| 71 | + "Registering to vote in Oregon is quick and simple, and can be done online, by mail, or in person[^1]", |
| 72 | + "To register in Oregon, you must be a citizen of the United States, a resident of Oregon, and at least 16 years old (you must be 18 by Election Day to vote)[^2]", |
| 73 | + "The deadline to register to vote is 21 days before Election Day[^1]", |
| 74 | + "For the November 5, 2024 election, the online registration deadline is October 15, 2024[^4]", |
| 75 | + "If you do not have a valid Oregon ID or Social Security number, you can find acceptable alternative identification online[^5]" |
| 76 | + ], |
| 77 | + "relatedQueries": [ |
| 78 | + "What are the eligibility requirements to register to vote in Oregon?", |
| 79 | + "How can I update my voter registration information in Oregon?", |
| 80 | + "What is the deadline for voter registration in Oregon for upcoming elections?", |
| 81 | + "Can I register to vote in Oregon if I am not a U.S. citizen?", |
| 82 | + "What are the different ways to vote in Oregon after registering?" |
| 83 | + ], |
| 84 | + "report": "## How to Register to Vote in Oregon\n\n### Registration Methods\nOregon offers multiple convenient ways to register to vote:\n- **Online**: \n - Use the [My Vote](https://sos.oregon.gov/voting/Pages/voteinor.aspx) tool if you have an Oregon driver license or state ID.\n- **By Mail**: \n - Download and complete the voter registration form, which is available in various languages.\n- **In Person**: \n - Register at your local county elections office or at designated state agencies like the DMV[^1][^2].\n\n### Eligibility Requirements\nTo register in Oregon, you must meet the following criteria:\n- Be a citizen of the United States.\n- Be a resident of Oregon.\n- Be at least 16 years old (you must be 18 by Election Day to vote) [^2].\n\n### Important Deadlines\n- The deadline to register to vote is **21 days before Election Day**.\n- For the upcoming elections, ensure your registration is completed by the specified deadlines:\n - For the May 21, 2024, Primary Election, your registration must be postmarked by April 30, 2024[^5].\n\n### Updating Your Registration\nIf you need to update your voter registration, you can do so online if you have an Oregon driver license or state ID. Simply visit the My Vote tool, enter your details, and follow the prompts to update your information[^3].\n\n## References\n[^1]: State of Oregon: Elections - Voting in Oregon \n[^2]: Register to Vote Online in Oregon - Vote.org \n[^3]: State of Oregon: Voting - Update Voter Registration Information \n[^4]: How to register in Oregon | Vote.gov \n[^5]: Voter Registration Information - State of Oregon: Voting & Elections", |
| 85 | +} |
| 86 | + "error": "" |
| 87 | +``` |
0 commit comments