Skip to main content
Ctrl+K

πŸ¦œπŸ”— LangChain 0.0.107

Getting Started

  • Quickstart Guide

Modules

  • Prompt Templates
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Create a custom prompt template
      • Create a custom example selector
      • Provide few shot examples to a prompt
      • Prompt Serialization
      • Example Selectors
    • Reference
      • PromptTemplates
      • Example Selector
  • LLMs
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Generic Functionality
        • Custom LLM
        • Fake LLM
        • LLM Caching
        • LLM Serialization
        • Token Usage Tracking
      • Integrations
        • AI21
        • Aleph Alpha
        • Anthropic
        • Azure OpenAI LLM Example
        • Banana
        • CerebriumAI LLM Example
        • Cohere
        • DeepInfra LLM Example
        • ForefrontAI LLM Example
        • GooseAI LLM Example
        • Hugging Face Hub
        • Manifest
        • Modal
        • OpenAI
        • Petals LLM Example
        • PromptLayer OpenAI
        • Self-Hosted Models via Runhouse
        • StochasticAI
        • Writer
      • Async API for LLM
      • Streaming with LLMs
    • Reference
  • Document Loaders
    • Key Concepts
    • How To Guides
      • CoNLL-U
      • Airbyte JSON
      • AZLyrics
      • College Confidential
      • Copy Paste
      • CSV Loader
      • Directory Loader
      • Email
      • EverNote
      • Facebook Chat
      • GCS Directory
      • GCS File Storage
      • GitBook
      • Google Drive
      • Gutenberg
      • Hacker News
      • HTML
      • iFixit
      • Images
      • IMSDb
      • Markdown
      • Microsoft Word
      • Notebook
      • Notion
      • Obsidian
      • Online PDF
      • PDF
      • PowerPoint
      • ReadTheDocs Documentation
      • Roam
      • s3 Directory
      • s3 File
      • Subtitle Files
      • Telegram
      • Unstructured File Loader
      • URL
      • Web Base
      • Word Documents
      • YouTube
  • Utils
    • Key Concepts
    • Generic Utilities
      • Bash
      • Bing Search
      • Google Search
      • Google Serper API
      • IFTTT WebHooks
      • Python REPL
      • Requests
      • SearxNG Search API
      • SerpAPI
      • Wolfram Alpha
    • Reference
      • Python REPL
      • SerpAPI
      • SearxNG Search
      • Docstore
      • Text Splitter
      • Embeddings
      • VectorStores
  • Indexes
    • Getting Started
    • Key Concepts
    • How To Guides
      • Embeddings
      • Hypothetical Document Embeddings
      • Text Splitter
      • VectorStores
      • AtlasDB
      • Chroma
      • Deep Lake
      • ElasticSearch
      • FAISS
      • Milvus
      • OpenSearch
      • Pinecone
      • Qdrant
      • Weaviate
      • Analyze Document
      • Chat Vector DB
      • Graph QA
      • Question Answering with Sources
      • Question Answering
      • Summarization
      • Vector DB Question/Answering
      • VectorDB Question Answering with Sources
      • Vector DB Text Generation
  • Chains
    • Getting Started
    • How-To Guides
      • Generic Chains
        • Loading from LangChainHub
        • LLM Chain
        • Sequential Chains
        • Serialization
        • Transformation Chain
      • Utility Chains
        • API Chains
        • Self-Critique Chain with Constitutional AI
        • BashChain
        • LLMCheckerChain
        • LLM Math
        • LLMRequestsChain
        • LLMSummarizationCheckerChain
        • Moderation
        • PAL
        • SQLite example
      • Async API for Chain
    • Key Concepts
    • Reference
  • Agents
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Agents and Vectorstores
      • Async API for Agent
      • Custom Agent
      • Defining Custom Tools
      • Intermediate Steps
      • Loading from LangChainHub
      • Max Iterations
      • Multi Input Tools
      • Search Tools
      • Serialization
      • CSV Agent
      • JSON Agent
      • OpenAPI Agent
      • Pandas Dataframe Agent
      • Python Agent
      • SQL Database Agent
      • Vectorstore Agent
      • MRKL
      • MRKL Chat
      • ReAct
      • Self Ask With Search
    • Reference
  • Memory
    • Getting Started
    • Key Concepts
    • How-To Guides
      • ConversationBufferMemory
      • ConversationBufferWindowMemory
      • Entity Memory
      • Conversation Knowledge Graph Memory
      • ConversationSummaryMemory
      • ConversationSummaryBufferMemory
      • Adding Memory To an LLMChain
      • Adding Memory to a Multi-Input Chain
      • Adding Memory to an Agent
      • ChatGPT Clone
      • Conversation Agent
      • Conversational Memory Customization
      • Custom Memory
      • Multiple Memory
  • Chat
    • Getting Started
    • Key Concepts
    • How-To Guides
      • Agent
      • Chat Vector DB
      • Few Shot Examples
      • Memory
      • PromptLayer ChatOpenAI
      • Streaming
      • Vector DB Question/Answering
      • VectorDB Question Answering with Sources

Use Cases

  • Agents
  • Chatbots
  • Generate Examples
  • Data Augmented Generation
  • Question Answering
  • Summarization
  • Evaluation
    • Data Augmented Question Answering
    • Using Hugging Face Datasets
    • Question Answering
  • Model Comparison

Reference

  • Installation
  • Integrations
  • API References
    • Prompts
      • PromptTemplates
      • Example Selector
    • Utilities
      • Python REPL
      • SerpAPI
      • SearxNG Search
      • Docstore
      • Text Splitter
      • Embeddings
      • VectorStores
    • Chains
    • Agents

Ecosystem

  • LangChain Ecosystem
    • AI21 Labs
    • AtlasDB
    • Banana
    • CerebriumAI
    • Chroma
    • Cohere
    • DeepInfra
    • Deep Lake
    • ForefrontAI
    • Google Search Wrapper
    • Google Serper Wrapper
    • GooseAI
    • Graphsignal
    • Hazy Research
    • Helicone
    • Hugging Face
    • Modal
    • NLPCloud
    • OpenAI
    • OpenSearch
    • Petals
    • Pinecone
    • PromptLayer
    • Runhouse
    • SearxNG Search API
    • SerpAPI
    • StochasticAI
    • Unstructured
    • Weaviate
    • Wolfram Alpha Wrapper
    • Writer

Additional Resources

  • LangChainHub
  • Glossary
  • LangChain Gallery
  • Deployments
  • Tracing
  • Discord
  • Production Support
  • .ipynb

Google Search

Contents

  • Number of Results
  • Metadata Results

Google Search#

This notebook goes over how to use the google search component.

First, you need to set up the proper API keys and environment variables. To set it up, follow the instructions found here.

Then we will need to set some environment variables.

import os
os.environ["GOOGLE_CSE_ID"] = ""
os.environ["GOOGLE_API_KEY"] = ""
from langchain.utilities import GoogleSearchAPIWrapper
search = GoogleSearchAPIWrapper()
search.run("Obama's first name?")
'1 Child\'s First Name. 2. 6. 7d. Street Address. 71. (Type or print). BARACK. Sex. 3. This Birth. 4. If Twin or Triplet,. Was Child Born. Barack Hussein Obama II is an American retired politician who served as the 44th president of the United States from 2009 to 2017. His full name is Barack Hussein Obama II. Since the β€œII” is simply because he was named for his father, his last name is Obama. Feb 9, 2015 ... Michael Jordan misspelled Barack Obama\'s first name on 50th-birthday gift ... Knowing Obama is a Chicagoan and huge basketball fan,\xa0... Aug 18, 2017 ... It took him several seconds and multiple clues to remember former President Barack Obama\'s first name. Miller knew that every answer had to end\xa0... First Lady Michelle LaVaughn Robinson Obama is a lawyer, writer, and the wife of the 44th President, Barack Obama. She is the first African-American First\xa0... Barack Obama, in full Barack Hussein Obama II, (born August 4, 1961, Honolulu, Hawaii, U.S.), 44th president of the United States (2009–17) and the first\xa0... When Barack Obama was elected president in 2008, he became the first African American to hold ... The Middle East remained a key foreign policy challenge. Feb 27, 2020 ... President Barack Obama was born Barack Hussein Obama, II, as shown here on his birth certificate here . As reported by Reuters here , his\xa0... Jan 16, 2007 ... 4, 1961, in Honolulu. His first name means "one who is blessed" in Swahili. While Obama\'s father, Barack Hussein Obama Sr., was from Kenya, his\xa0...'

Number of Results#

You can use the k parameter to set the number of results

search = GoogleSearchAPIWrapper(k=1)
search.run("python")
'The official home of the Python Programming Language.'

β€˜The official home of the Python Programming Language.’

Metadata Results#

Run query through GoogleSearch and return snippet, title, and link metadata.

  • Snippet: The description of the result.

  • Title: The title of the result.

  • Link: The link to the result.

search = GoogleSearchAPIWrapper()
search.results("apples", 5)
[{'snippet': 'Discover the innovative world of Apple and shop everything iPhone, iPad, Apple Watch, Mac, and Apple TV, plus explore accessories, entertainment,\xa0...',
  'title': 'Apple',
  'link': 'https://www.apple.com/'},
 {'snippet': "Jul 10, 2022 ... Whether or not you're up on your apple trivia, no doubt you know how delicious this popular fruit is, and how nutritious. Apples are rich in\xa0...",
  'title': '25 Types of Apples and What to Make With Them - Parade ...',
  'link': 'https://parade.com/1330308/bethlipton/types-of-apples/'},
 {'snippet': 'An apple is an edible fruit produced by an apple tree (Malus domestica). Apple trees are cultivated worldwide and are the most widely grown species in the\xa0...',
  'title': 'Apple - Wikipedia',
  'link': 'https://en.wikipedia.org/wiki/Apple'},
 {'snippet': 'Apples are a popular fruit. They contain antioxidants, vitamins, dietary fiber, and a range of other nutrients. Due to their varied nutrient content,\xa0...',
  'title': 'Apples: Benefits, nutrition, and tips',
  'link': 'https://www.medicalnewstoday.com/articles/267290'},
 {'snippet': "An apple is a crunchy, bright-colored fruit, one of the most popular in the United States. You've probably heard the age-old saying, β€œAn apple a day keeps\xa0...",
  'title': 'Apples: Nutrition & Health Benefits',
  'link': 'https://www.webmd.com/food-recipes/benefits-apples'}]

previous

Bing Search

next

Google Serper API

Contents
  • Number of Results
  • Metadata Results

By Harrison Chase

Β© Copyright 2022, Harrison Chase.