mirror of https://github.com/hwchase17/langchain
Merge 0198c76edc
into 242eeb537f
commit
5a8db2e49a
@ -0,0 +1,370 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "sqhc5D5Go0w6"
|
||||
},
|
||||
"source": [
|
||||
"# Google Cloud Vertex AI Search Check Grounding API\n",
|
||||
"\n",
|
||||
"> The [Vertex AI Check Grounding API](https://cloud.google.com/generative-ai-app-builder/docs/check-grounding) is one of the standalone APIs in [Vertex AI Agent Builder](https://cloud.google.com/generative-ai-app-builder/docs/builder-apis). It is used to determine how grounded a piece of text (called an answer candidate) is in a given set of reference texts (called facts).\n",
|
||||
"\n",
|
||||
"> The Check Grounding API returns an overall support score of 0 to 1, which indicates how much the answer candidate agrees with the given facts. The response also includes citations to the facts supporting each claim in the answer candidate.\n",
|
||||
"\n",
|
||||
"> You can use the Check Grounding API for checking any piece of text. It could be a human-generated blurb or a machine-generated response. A typical use case would be to check an LLM-generated response with respect to a given set of facts. Among other things, the citations generated by the API would help distinguish hallucinated claim in the response from grounded claims.\n",
|
||||
"\n",
|
||||
"> For more information, see [Check Grounding](https://cloud.google.com/generative-ai-app-builder/docs/check-grounding)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "IOFsN738jZIW"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%pip install --upgrade --quiet langchain langchain-community langchain-google-community langchain-google-vertexai langchain-chroma langchain-text-splitters google-cloud-discoveryengine langchain-google-community['vertexaisearch'] rich"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "7n58HgXzkYh-"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"\n",
|
||||
"if \"google.colab\" in sys.modules:\n",
|
||||
" from google.colab import auth\n",
|
||||
"\n",
|
||||
" auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "SMQTbJiwkaQi"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"REGION = \"us-central1\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"# @title # Initialize GCP project for Vertex AI\n",
|
||||
"from google.cloud import aiplatform\n",
|
||||
"\n",
|
||||
"aiplatform.init(project=PROJECT_ID, location=REGION)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "tdKMyz4ipgeD"
|
||||
},
|
||||
"source": [
|
||||
"### Load and Prepare data\n",
|
||||
"\n",
|
||||
"For this example, we will be using the [Google Wiki page](https://en.wikipedia.org/wiki/Google) to demonstrate how the Vertex Check Grounding API works.\n",
|
||||
"\n",
|
||||
"The embeddings are created using the [Vertex AI Embeddings API](https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/get-text-embeddings#supported_models) model - `textembedding-gecko@003`"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "Z79-hp56kmfG",
|
||||
"outputId": "a37b44ad-d0c4-4242-e9fa-83bb23b9c696"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Your 1 documents have been split into 269 chunks\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_chroma import Chroma\n",
|
||||
"from langchain_community.document_loaders import WebBaseLoader\n",
|
||||
"from langchain_google_vertexai import VertexAIEmbeddings\n",
|
||||
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
|
||||
"\n",
|
||||
"vectordb = None\n",
|
||||
"# Load wiki page\n",
|
||||
"loader = WebBaseLoader(\"https://en.wikipedia.org/wiki/Google\")\n",
|
||||
"data = loader.load()\n",
|
||||
"\n",
|
||||
"# Split doc into chunks\n",
|
||||
"text_splitter = RecursiveCharacterTextSplitter(chunk_size=800, chunk_overlap=5)\n",
|
||||
"splits = text_splitter.split_documents(data)\n",
|
||||
"\n",
|
||||
"print(f\"Your {len(data)} documents have been split into {len(splits)} chunks\")\n",
|
||||
"\n",
|
||||
"if vectordb is not None: # delete existing vectordb if it already exists\n",
|
||||
" vectordb.delete_collection()\n",
|
||||
"\n",
|
||||
"embedding = VertexAIEmbeddings(model_name=\"textembedding-gecko@003\")\n",
|
||||
"vectordb = Chroma.from_documents(documents=splits, embedding=embedding)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "k_SK-ejzpqL6"
|
||||
},
|
||||
"source": [
|
||||
"### Testing out the Vertex AI Check Grounding API\n",
|
||||
"\n",
|
||||
"Let's setup a standard RAG pipeline of `query -> vector db -> retrieved documents -> Vertex AI LLM` to generate the answer. After the answer is generated from the LLM, pass this `answer_candidate` and the `retrieved_docs` from `vectordb` as `facts` to check how grounded the response from the LLM is."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "tC_04Sp8kyoc"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from typing import List\n",
|
||||
"\n",
|
||||
"from langchain.chains import LLMChain\n",
|
||||
"from langchain.docstore.document import Document\n",
|
||||
"from langchain_core.output_parsers import StrOutputParser\n",
|
||||
"from langchain_core.prompts import PromptTemplate\n",
|
||||
"from langchain_core.runnables import (\n",
|
||||
" ConfigurableField,\n",
|
||||
" RunnableParallel,\n",
|
||||
" RunnablePassthrough,\n",
|
||||
" chain,\n",
|
||||
")\n",
|
||||
"from langchain_google_community import VertexAICheckGroundingWrapper\n",
|
||||
"from langchain_google_vertexai import VertexAI\n",
|
||||
"from rich import print\n",
|
||||
"\n",
|
||||
"llm = VertexAI(model_name=\"gemini-1.0-pro-001\", max_output_tokens=1024)\n",
|
||||
"\n",
|
||||
"retriever = vectordb.as_retriever(search_kwargs={\"k\": 5})\n",
|
||||
"\n",
|
||||
"template = \"\"\"Answer the question based only on the following context:\n",
|
||||
" {context}\n",
|
||||
"\n",
|
||||
" Question:\n",
|
||||
" {query} \"\"\"\n",
|
||||
"\n",
|
||||
"prompt = PromptTemplate.from_template(template)\n",
|
||||
"\n",
|
||||
"output_parser = VertexAICheckGroundingWrapper(\n",
|
||||
" project_id=PROJECT_ID,\n",
|
||||
" location_id=\"global\",\n",
|
||||
" grounding_config=\"default_grounding_config\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@chain\n",
|
||||
"def check_grounding_output_parser(answer_candidate: str, documents: List[Document]):\n",
|
||||
" return output_parser.with_config(configurable={\"documents\": documents}).invoke(\n",
|
||||
" answer_candidate\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"setup_and_retrieval = RunnableParallel(\n",
|
||||
" {\"context\": retriever, \"query\": RunnablePassthrough()}\n",
|
||||
")\n",
|
||||
"create_answer = prompt | llm\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@chain\n",
|
||||
"def qa_with_check_grounding(query):\n",
|
||||
" docs = setup_and_retrieval.invoke(query)\n",
|
||||
" answer_candidate = create_answer.invoke(docs)\n",
|
||||
" check_grounding_output = check_grounding_output_parser.invoke(\n",
|
||||
" answer_candidate, documents=docs[\"context\"]\n",
|
||||
" )\n",
|
||||
" return check_grounding_output"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "uurMZnwnqV_B"
|
||||
},
|
||||
"source": [
|
||||
"### Running the chain with Check Grounding API to verify the grounding\n",
|
||||
"\n",
|
||||
"As you can see from the `result`, we obtain the `support_score` of `~0.99` which indicates that LLM response is highly grounded.\n",
|
||||
"\n",
|
||||
"The `result` also shows the individual chunks that were used to verify the the various sentences in the `answer_candidate`. Even though we pass 5 facts to the Check Grounding API, only two `cited_chunks` are actually used in the answer generation.\n",
|
||||
"\n",
|
||||
"The `results` contains a final `answer_with_citations` that formats each claim with the respective `cited_chunks` that can be referred to easily.\n",
|
||||
"\n",
|
||||
"Notice that the second sentence does not contain any citation and hence is `ungrounded`. In your RAG pipeline, you can choose to remove this ungrounded sentence from the final answer that is shown to the user."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/",
|
||||
"height": 941
|
||||
},
|
||||
"id": "hq0ZT-YuqaUE",
|
||||
"outputId": "b5bf7234-ba1d-4936-f866-ccee0f229ebe"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">CheckGroundingResponse</span><span style=\"font-weight: bold\">(</span>\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">support_score</span>=<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.9919261932373047</span>,\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">cited_chunks</span>=<span style=\"font-weight: bold\">[</span>\n",
|
||||
" <span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'chunk_text'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'The name \"Google\" originated from a misspelling of \"googol\",[213][214] which refers to </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">the number represented by a 1 followed by one-hundred zeros. Page and Brin write in their original paper on </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">PageRank:[33] \"We chose our system name, Google, because it is a common spelling of googol, or 10100[,] and fits </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">well with our goal of building very large-scale search engines.\" Having found its way increasingly into everyday </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">language, the verb \"google\" was added to the Merriam Webster Collegiate Dictionary and the Oxford English </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">Dictionary in 2006, meaning \"to use the Google search engine to obtain information on the Internet.\"[215][216] </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">Google\\'s mission statement, from the outset, was \"to organize the world\\'s information and make it universally </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">accessible and useful\",[217] and its unofficial'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'source'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Document</span><span style=\"font-weight: bold\">(</span>\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">page_content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'The name \"Google\" originated from a misspelling of \"googol\",[213][214] which refers </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">to the number represented by a 1 followed by one-hundred zeros. Page and Brin write in their original paper on </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">PageRank:[33] \"We chose our system name, Google, because it is a common spelling of googol, or 10100[,] and fits </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">well with our goal of building very large-scale search engines.\" Having found its way increasingly into everyday </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">language, the verb \"google\" was added to the Merriam Webster Collegiate Dictionary and the Oxford English </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">Dictionary in 2006, meaning \"to use the Google search engine to obtain information on the Internet.\"[215][216] </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">Google\\'s mission statement, from the outset, was \"to organize the world\\'s information and make it universally </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">accessible and useful\",[217] and its unofficial'</span>,\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'language'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'en'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'source'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'https://en.wikipedia.org/wiki/Google'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Google - Wikipedia'</span>\n",
|
||||
" <span style=\"font-weight: bold\">}</span>\n",
|
||||
" <span style=\"font-weight: bold\">)</span>\n",
|
||||
" <span style=\"font-weight: bold\">}</span>,\n",
|
||||
" <span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'chunk_text'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Eventually, they changed the name to Google; the name of the search engine was a </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">misspelling of the word googol,[21][36][37] a very large number written 10100 (1 followed by 100 zeros), picked to </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">signify that the search engine was intended to provide large quantities of information.[38]'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'source'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Document</span><span style=\"font-weight: bold\">(</span>\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">page_content</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'Eventually, they changed the name to Google; the name of the search engine was a </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">misspelling of the word googol,[21][36][37] a very large number written 10100 (1 followed by 100 zeros), picked to </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">signify that the search engine was intended to provide large quantities of information.[38]'</span>,\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">metadata</span>=<span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'language'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'en'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'source'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'https://en.wikipedia.org/wiki/Google'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'title'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Google - Wikipedia'</span>\n",
|
||||
" <span style=\"font-weight: bold\">}</span>\n",
|
||||
" <span style=\"font-weight: bold\">)</span>\n",
|
||||
" <span style=\"font-weight: bold\">}</span>\n",
|
||||
" <span style=\"font-weight: bold\">]</span>,\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">claims</span>=<span style=\"font-weight: bold\">[</span>\n",
|
||||
" <span style=\"font-weight: bold\">{</span>\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'start_pos'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'end_pos'</span>: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">137</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'claim_text'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'The name \"Google\" originated from a misspelling of \"googol\", which refers to the number </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">represented by a 1 followed by one-hundred zeros.'</span>,\n",
|
||||
" <span style=\"color: #008000; text-decoration-color: #008000\">'citation_indices'</span>: <span style=\"font-weight: bold\">[</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0</span>, <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span><span style=\"font-weight: bold\">]</span>\n",
|
||||
" <span style=\"font-weight: bold\">}</span>\n",
|
||||
" <span style=\"font-weight: bold\">]</span>,\n",
|
||||
" <span style=\"color: #808000; text-decoration-color: #808000\">answer_with_citations</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'The name \"Google\" originated from a misspelling of \"googol\", which refers to the number </span>\n",
|
||||
"<span style=\"color: #008000; text-decoration-color: #008000\">represented by a 1 followed by one-hundred zeros.[0][1]'</span>\n",
|
||||
"<span style=\"font-weight: bold\">)</span>\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"\u001b[1;35mCheckGroundingResponse\u001b[0m\u001b[1m(\u001b[0m\n",
|
||||
" \u001b[33msupport_score\u001b[0m=\u001b[1;36m0\u001b[0m\u001b[1;36m.9919261932373047\u001b[0m,\n",
|
||||
" \u001b[33mcited_chunks\u001b[0m=\u001b[1m[\u001b[0m\n",
|
||||
" \u001b[1m{\u001b[0m\n",
|
||||
" \u001b[32m'chunk_text'\u001b[0m: \u001b[32m'The name \"Google\" originated from a misspelling of \"googol\",\u001b[0m\u001b[32m[\u001b[0m\u001b[32m213\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m214\u001b[0m\u001b[32m]\u001b[0m\u001b[32m which refers to \u001b[0m\n",
|
||||
"\u001b[32mthe number represented by a 1 followed by one-hundred zeros. Page and Brin write in their original paper on \u001b[0m\n",
|
||||
"\u001b[32mPageRank:\u001b[0m\u001b[32m[\u001b[0m\u001b[32m33\u001b[0m\u001b[32m]\u001b[0m\u001b[32m \"We chose our system name, Google, because it is a common spelling of googol, or 10100\u001b[0m\u001b[32m[\u001b[0m\u001b[32m,\u001b[0m\u001b[32m]\u001b[0m\u001b[32m and fits \u001b[0m\n",
|
||||
"\u001b[32mwell with our goal of building very large-scale search engines.\" Having found its way increasingly into everyday \u001b[0m\n",
|
||||
"\u001b[32mlanguage, the verb \"google\" was added to the Merriam Webster Collegiate Dictionary and the Oxford English \u001b[0m\n",
|
||||
"\u001b[32mDictionary in 2006, meaning \"to use the Google search engine to obtain information on the Internet.\"\u001b[0m\u001b[32m[\u001b[0m\u001b[32m215\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m216\u001b[0m\u001b[32m]\u001b[0m\u001b[32m \u001b[0m\n",
|
||||
"\u001b[32mGoogle\\'s mission statement, from the outset, was \"to organize the world\\'s information and make it universally \u001b[0m\n",
|
||||
"\u001b[32maccessible and useful\",\u001b[0m\u001b[32m[\u001b[0m\u001b[32m217\u001b[0m\u001b[32m]\u001b[0m\u001b[32m and its unofficial'\u001b[0m,\n",
|
||||
" \u001b[32m'source'\u001b[0m: \u001b[1;35mDocument\u001b[0m\u001b[1m(\u001b[0m\n",
|
||||
" \u001b[33mpage_content\u001b[0m=\u001b[32m'The name \"Google\" originated from a misspelling of \"googol\",\u001b[0m\u001b[32m[\u001b[0m\u001b[32m213\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m214\u001b[0m\u001b[32m]\u001b[0m\u001b[32m which refers \u001b[0m\n",
|
||||
"\u001b[32mto the number represented by a 1 followed by one-hundred zeros. Page and Brin write in their original paper on \u001b[0m\n",
|
||||
"\u001b[32mPageRank:\u001b[0m\u001b[32m[\u001b[0m\u001b[32m33\u001b[0m\u001b[32m]\u001b[0m\u001b[32m \"We chose our system name, Google, because it is a common spelling of googol, or 10100\u001b[0m\u001b[32m[\u001b[0m\u001b[32m,\u001b[0m\u001b[32m]\u001b[0m\u001b[32m and fits \u001b[0m\n",
|
||||
"\u001b[32mwell with our goal of building very large-scale search engines.\" Having found its way increasingly into everyday \u001b[0m\n",
|
||||
"\u001b[32mlanguage, the verb \"google\" was added to the Merriam Webster Collegiate Dictionary and the Oxford English \u001b[0m\n",
|
||||
"\u001b[32mDictionary in 2006, meaning \"to use the Google search engine to obtain information on the Internet.\"\u001b[0m\u001b[32m[\u001b[0m\u001b[32m215\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m216\u001b[0m\u001b[32m]\u001b[0m\u001b[32m \u001b[0m\n",
|
||||
"\u001b[32mGoogle\\'s mission statement, from the outset, was \"to organize the world\\'s information and make it universally \u001b[0m\n",
|
||||
"\u001b[32maccessible and useful\",\u001b[0m\u001b[32m[\u001b[0m\u001b[32m217\u001b[0m\u001b[32m]\u001b[0m\u001b[32m and its unofficial'\u001b[0m,\n",
|
||||
" \u001b[33mmetadata\u001b[0m=\u001b[1m{\u001b[0m\n",
|
||||
" \u001b[32m'language'\u001b[0m: \u001b[32m'en'\u001b[0m,\n",
|
||||
" \u001b[32m'source'\u001b[0m: \u001b[32m'https://en.wikipedia.org/wiki/Google'\u001b[0m,\n",
|
||||
" \u001b[32m'title'\u001b[0m: \u001b[32m'Google - Wikipedia'\u001b[0m\n",
|
||||
" \u001b[1m}\u001b[0m\n",
|
||||
" \u001b[1m)\u001b[0m\n",
|
||||
" \u001b[1m}\u001b[0m,\n",
|
||||
" \u001b[1m{\u001b[0m\n",
|
||||
" \u001b[32m'chunk_text'\u001b[0m: \u001b[32m'Eventually, they changed the name to Google; the name of the search engine was a \u001b[0m\n",
|
||||
"\u001b[32mmisspelling of the word googol,\u001b[0m\u001b[32m[\u001b[0m\u001b[32m21\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m36\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m37\u001b[0m\u001b[32m]\u001b[0m\u001b[32m a very large number written 10100 \u001b[0m\u001b[32m(\u001b[0m\u001b[32m1 followed by 100 zeros\u001b[0m\u001b[32m)\u001b[0m\u001b[32m, picked to \u001b[0m\n",
|
||||
"\u001b[32msignify that the search engine was intended to provide large quantities of information.\u001b[0m\u001b[32m[\u001b[0m\u001b[32m38\u001b[0m\u001b[32m]\u001b[0m\u001b[32m'\u001b[0m,\n",
|
||||
" \u001b[32m'source'\u001b[0m: \u001b[1;35mDocument\u001b[0m\u001b[1m(\u001b[0m\n",
|
||||
" \u001b[33mpage_content\u001b[0m=\u001b[32m'Eventually, they changed the name to Google; the name of the search engine was a \u001b[0m\n",
|
||||
"\u001b[32mmisspelling of the word googol,\u001b[0m\u001b[32m[\u001b[0m\u001b[32m21\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m36\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m37\u001b[0m\u001b[32m]\u001b[0m\u001b[32m a very large number written 10100 \u001b[0m\u001b[32m(\u001b[0m\u001b[32m1 followed by 100 zeros\u001b[0m\u001b[32m)\u001b[0m\u001b[32m, picked to \u001b[0m\n",
|
||||
"\u001b[32msignify that the search engine was intended to provide large quantities of information.\u001b[0m\u001b[32m[\u001b[0m\u001b[32m38\u001b[0m\u001b[32m]\u001b[0m\u001b[32m'\u001b[0m,\n",
|
||||
" \u001b[33mmetadata\u001b[0m=\u001b[1m{\u001b[0m\n",
|
||||
" \u001b[32m'language'\u001b[0m: \u001b[32m'en'\u001b[0m,\n",
|
||||
" \u001b[32m'source'\u001b[0m: \u001b[32m'https://en.wikipedia.org/wiki/Google'\u001b[0m,\n",
|
||||
" \u001b[32m'title'\u001b[0m: \u001b[32m'Google - Wikipedia'\u001b[0m\n",
|
||||
" \u001b[1m}\u001b[0m\n",
|
||||
" \u001b[1m)\u001b[0m\n",
|
||||
" \u001b[1m}\u001b[0m\n",
|
||||
" \u001b[1m]\u001b[0m,\n",
|
||||
" \u001b[33mclaims\u001b[0m=\u001b[1m[\u001b[0m\n",
|
||||
" \u001b[1m{\u001b[0m\n",
|
||||
" \u001b[32m'start_pos'\u001b[0m: \u001b[1;36m0\u001b[0m,\n",
|
||||
" \u001b[32m'end_pos'\u001b[0m: \u001b[1;36m137\u001b[0m,\n",
|
||||
" \u001b[32m'claim_text'\u001b[0m: \u001b[32m'The name \"Google\" originated from a misspelling of \"googol\", which refers to the number \u001b[0m\n",
|
||||
"\u001b[32mrepresented by a 1 followed by one-hundred zeros.'\u001b[0m,\n",
|
||||
" \u001b[32m'citation_indices'\u001b[0m: \u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m, \u001b[1;36m1\u001b[0m\u001b[1m]\u001b[0m\n",
|
||||
" \u001b[1m}\u001b[0m\n",
|
||||
" \u001b[1m]\u001b[0m,\n",
|
||||
" \u001b[33manswer_with_citations\u001b[0m=\u001b[32m'The name \"Google\" originated from a misspelling of \"googol\", which refers to the number \u001b[0m\n",
|
||||
"\u001b[32mrepresented by a 1 followed by one-hundred zeros.\u001b[0m\u001b[32m[\u001b[0m\u001b[32m0\u001b[0m\u001b[32m]\u001b[0m\u001b[32m[\u001b[0m\u001b[32m1\u001b[0m\u001b[32m]\u001b[0m\u001b[32m'\u001b[0m\n",
|
||||
"\u001b[1m)\u001b[0m\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"result = qa_with_check_grounding.invoke(\"how did the name google originate?\")\n",
|
||||
"print(result)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
Loading…
Reference in New Issue