id
stringlengths
14
17
text
stringlengths
42
2.1k
4e9727215e95-1000
You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]);You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]);PreviousYouTube transcriptsNexthtml-to-textText splittersGet started with text splittersCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc. Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationsText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersOn this pageDocument transformersOnce you've loaded documents, you'll often want to transform them to better suit your application. The simplest example is you may want to split a long document into smaller chunks that can fit into your model's context window. LangChain
4e9727215e95-1001
has a number of built-in document transformers that make it easy to split, combine, filter, and otherwise manipulate documents.Text splitters​When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What "semantically related" means could depend on the type of text.
4e9727215e95-1002
This notebook showcases several ways to do that.At a high level, text splitters work as following:Split the text up into small, semantically meaningful chunks (often sentences).Start combining these small chunks into a larger chunk until you reach a certain size (as measured by some function).Once you reach that size, make that chunk its own piece of text and then start creating a new chunk of text with some overlap (to keep context between chunks).That means there are two different axes along which you can customize your text splitter:How the text is splitHow the chunk size is measuredGet started with text splitters​The recommended TextSplitter is the RecursiveCharacterTextSplitter. This will split documents recursively by different characters - starting with "\n\n", then "\n", then " ". This is nice because it will try to keep all the semantically relevant content in the same place for as long as possible.Important parameters to know here are chunkSize and chunkOverlap. chunkSize controls the max size (in terms of number of characters) of the final documents. chunkOverlap specifies how much overlap there should be between chunks. This is often helpful to make sure that the text isn't split weirdly. In the example below we set these values to be small (for illustration purposes), but in practice they default to 1000 and 200 respectively.import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are?
4e9727215e95-1003
You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]);You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]);PreviousYouTube transcriptsNexthtml-to-textText splittersGet started with text splitters Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationsText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI reference Text splitters ModulesData connectionDocument transformersOn this pageDocument transformersOnce you've loaded documents, you'll often want to transform them to better suit your application. The simplest example is you may want to split a long document into smaller chunks that can fit into your model's context window. LangChain
4e9727215e95-1004
has a number of built-in document transformers that make it easy to split, combine, filter, and otherwise manipulate documents.Text splitters​When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What "semantically related" means could depend on the type of text.
4e9727215e95-1005
This notebook showcases several ways to do that.At a high level, text splitters work as following:Split the text up into small, semantically meaningful chunks (often sentences).Start combining these small chunks into a larger chunk until you reach a certain size (as measured by some function).Once you reach that size, make that chunk its own piece of text and then start creating a new chunk of text with some overlap (to keep context between chunks).That means there are two different axes along which you can customize your text splitter:How the text is splitHow the chunk size is measuredGet started with text splitters​The recommended TextSplitter is the RecursiveCharacterTextSplitter. This will split documents recursively by different characters - starting with "\n\n", then "\n", then " ". This is nice because it will try to keep all the semantically relevant content in the same place for as long as possible.Important parameters to know here are chunkSize and chunkOverlap. chunkSize controls the max size (in terms of number of characters) of the final documents. chunkOverlap specifies how much overlap there should be between chunks. This is often helpful to make sure that the text isn't split weirdly. In the example below we set these values to be small (for illustration purposes), but in practice they default to 1000 and 200 respectively.import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are?
4e9727215e95-1006
You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]);You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]);PreviousYouTube transcriptsNexthtml-to-textText splittersGet started with text splitters ModulesData connectionDocument transformersOn this pageDocument transformersOnce you've loaded documents, you'll often want to transform them to better suit your application. The simplest example is you may want to split a long document into smaller chunks that can fit into your model's context window. LangChain has a number of built-in document transformers that make it easy to split, combine, filter, and otherwise manipulate documents.Text splitters​When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What "semantically related" means could depend on the type of text.
4e9727215e95-1007
This notebook showcases several ways to do that.At a high level, text splitters work as following:Split the text up into small, semantically meaningful chunks (often sentences).Start combining these small chunks into a larger chunk until you reach a certain size (as measured by some function).Once you reach that size, make that chunk its own piece of text and then start creating a new chunk of text with some overlap (to keep context between chunks).That means there are two different axes along which you can customize your text splitter:How the text is splitHow the chunk size is measuredGet started with text splitters​The recommended TextSplitter is the RecursiveCharacterTextSplitter. This will split documents recursively by different characters - starting with "\n\n", then "\n", then " ". This is nice because it will try to keep all the semantically relevant content in the same place for as long as possible.Important parameters to know here are chunkSize and chunkOverlap. chunkSize controls the max size (in terms of number of characters) of the final documents. chunkOverlap specifies how much overlap there should be between chunks. This is often helpful to make sure that the text isn't split weirdly. In the example below we set these values to be small (for illustration purposes), but in practice they default to 1000 and 200 respectively.import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are?
4e9727215e95-1008
You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]);You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]);PreviousYouTube transcriptsNexthtml-to-text Document transformersOnce you've loaded documents, you'll often want to transform them to better suit your application. The simplest example is you may want to split a long document into smaller chunks that can fit into your model's context window. LangChain has a number of built-in document transformers that make it easy to split, combine, filter, and otherwise manipulate documents.Text splitters​When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What "semantically related" means could depend on the type of text.
4e9727215e95-1009
This notebook showcases several ways to do that.At a high level, text splitters work as following:Split the text up into small, semantically meaningful chunks (often sentences).Start combining these small chunks into a larger chunk until you reach a certain size (as measured by some function).Once you reach that size, make that chunk its own piece of text and then start creating a new chunk of text with some overlap (to keep context between chunks).That means there are two different axes along which you can customize your text splitter:How the text is splitHow the chunk size is measuredGet started with text splitters​The recommended TextSplitter is the RecursiveCharacterTextSplitter. This will split documents recursively by different characters - starting with "\n\n", then "\n", then " ". This is nice because it will try to keep all the semantically relevant content in the same place for as long as possible.Important parameters to know here are chunkSize and chunkOverlap. chunkSize controls the max size (in terms of number of characters) of the final documents. chunkOverlap specifies how much overlap there should be between chunks. This is often helpful to make sure that the text isn't split weirdly. In the example below we set these values to be small (for illustration purposes), but in practice they default to 1000 and 200 respectively.import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are?
4e9727215e95-1010
You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]);You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]); Once you've loaded documents, you'll often want to transform them to better suit your application. The simplest example is you may want to split a long document into smaller chunks that can fit into your model's context window. LangChain has a number of built-in document transformers that make it easy to split, combine, filter, and otherwise manipulate documents. When you want to deal with long pieces of text, it is necessary to split up that text into chunks. As simple as this sounds, there is a lot of potential complexity here. Ideally, you want to keep the semantically related pieces of text together. What "semantically related" means could depend on the type of text. This notebook showcases several ways to do that. At a high level, text splitters work as following:
4e9727215e95-1011
At a high level, text splitters work as following: That means there are two different axes along which you can customize your text splitter: The recommended TextSplitter is the RecursiveCharacterTextSplitter. This will split documents recursively by different characters - starting with "\n\n", then "\n", then " ". This is nice because it will try to keep all the semantically relevant content in the same place for as long as possible. Important parameters to know here are chunkSize and chunkOverlap. chunkSize controls the max size (in terms of number of characters) of the final documents. chunkOverlap specifies how much overlap there should be between chunks. This is often helpful to make sure that the text isn't split weirdly. In the example below we set these values to be small (for illustration purposes), but in practice they default to 1000 and 200 respectively. import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const output = await splitter.createDocuments([text]); You'll note that in the above example we are splitting a raw text string and getting back a list of documents. We can also split documents directly.
4e9727215e95-1012
import { Document } from "langchain/document";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const text = `Hi.\n\nI'm Harrison.\n\nHow? Are? You?\nOkay then f f f f.This is a weird text to write, but gotta test the splittingggg some how.\n\nBye!\n\n-H.`;const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 10, chunkOverlap: 1,});const docOutput = await splitter.splitDocuments([ new Document({ pageContent: text }),]); html-to-text Text splittersGet started with text splitters Page Title: html-to-text | 🦜️🔗 Langchain Paragraphs: Skip to main content🦜️🔗 LangChainDocsUse casesAPILangSmithPython DocsCTRLKGet startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrationshtml-to-textOn this pagehtml-to-textWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1013
Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the html-to-text npm package:npmYarnpnpmnpm install html-to-textyarn add html-to-textpnpm add html-to-textThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1014
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1015
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1016
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1017
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_textCustomization​You can pass the transformer any arguments accepted by the html-to-text package to customize how it works.PreviousDocument transformersNext@mozilla/readabilitySetupUsageCustomizationCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
4e9727215e95-1018
Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrationshtml-to-textOn this pagehtml-to-textWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the html-to-text npm package:npmYarnpnpmnpm install html-to-textyarn add html-to-textpnpm add html-to-textThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags,
4e9727215e95-1019
then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1020
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1021
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1022
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1023
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_textCustomization​You can pass the transformer any arguments accepted by the html-to-text package to customize how it works.PreviousDocument transformersNext@mozilla/readabilitySetupUsageCustomization Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI reference
4e9727215e95-1024
ModulesData connectionDocument transformersIntegrationshtml-to-textOn this pagehtml-to-textWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the html-to-text npm package:npmYarnpnpmnpm install html-to-textyarn add html-to-textpnpm add html-to-textThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1025
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1026
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1027
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1028
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_textCustomization​You can pass the transformer any arguments accepted by the html-to-text package to customize how it works.PreviousDocument transformersNext@mozilla/readabilitySetupUsageCustomization ModulesData connectionDocument transformersIntegrationshtml-to-textOn this pagehtml-to-textWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1029
Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the html-to-text npm package:npmYarnpnpmnpm install html-to-textyarn add html-to-textpnpm add html-to-textThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1030
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1031
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1032
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1033
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_textCustomization​You can pass the transformer any arguments accepted by the html-to-text package to customize how it works.PreviousDocument transformersNext@mozilla/readability html-to-textWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1034
Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the html-to-text npm package:npmYarnpnpmnpm install html-to-textyarn add html-to-textpnpm add html-to-textThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1035
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1036
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1037
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1038
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_textCustomization​You can pass the transformer any arguments accepted by the html-to-text package to customize how it works. When ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the HtmlToTextTransformer can result in more content-rich chunks, making retrieval more effective. You'll need to install the html-to-text npm package: Though not required for the transformer by itself, the below usage examples require cheerio for scraping:
4e9727215e95-1039
Though not required for the transformer by itself, the below usage examples require cheerio for scraping: The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks: import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";import { HtmlToTextTransformer } from "langchain/document_transformers/html_to_text";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new HtmlToTextTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1040
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1041
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1042
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak. If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object]
4e9727215e95-1043
loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/
4e9727215e95-1044
API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioRecursiveCharacterTextSplitter from langchain/text_splitterHtmlToTextTransformer from langchain/document_transformers/html_to_text You can pass the transformer any arguments accepted by the html-to-text package to customize how it works. @mozilla/readability SetupUsageCustomization Page Title: @mozilla/readability | 🦜️🔗 Langchain Paragraphs: Skip to main content🦜️🔗 LangChainDocsUse casesAPILangSmithPython DocsCTRLKGet startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrations@mozilla/readabilityOn this page@mozilla/readabilityWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the @mozilla/readability and the jsdom npm package:npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdomThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags,
4e9727215e95-1045
then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1046
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1047
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1048
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1049
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitterCustomization​You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works.Previoushtml-to-textNextOpenAI functions metadata taggerSetupUsageCustomizationCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
4e9727215e95-1050
Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrations@mozilla/readabilityOn this page@mozilla/readabilityWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the @mozilla/readability and the jsdom npm package:npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdomThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags,
4e9727215e95-1051
then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1052
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1053
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1054
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1055
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitterCustomization​You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works.Previoushtml-to-textNextOpenAI functions metadata taggerSetupUsageCustomization ModulesData connectionDocument transformersIntegrations@mozilla/readabilityOn this page@mozilla/readabilityWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1056
Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the @mozilla/readability and the jsdom npm package:npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdomThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1057
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1058
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1059
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1060
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitterCustomization​You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works.Previoushtml-to-textNextOpenAI functions metadata taggerSetupUsageCustomization ModulesData connectionDocument transformersIntegrations@mozilla/readabilityOn this page@mozilla/readabilityWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1061
Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the @mozilla/readability and the jsdom npm package:npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdomThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1062
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1063
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1064
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1065
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitterCustomization​You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works.Previoushtml-to-textNextOpenAI functions metadata tagger @mozilla/readabilityWhen ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics.
4e9727215e95-1066
Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective.Setup​You'll need to install the @mozilla/readability and the jsdom npm package:npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdomThough not required for the transformer by itself, the below usage examples require cheerio for scraping:npmYarnpnpmnpm install cheerioyarn add cheeriopnpm add cheerioUsage​The below example scrapes a Hacker News thread, splits it based on HTML tags to group chunks based on the semantic information from the tags, then extracts content from the individual chunks:import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1067
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1068
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1069
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak.
4e9727215e95-1070
If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitterCustomization​You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works. When ingesting HTML documents for later retrieval, we are often interested only in the actual content of the webpage rather than semantics. Stripping HTML tags from documents with the MozillaReadabilityTransformer can result in more content-rich chunks, making retrieval more effective. You'll need to install the @mozilla/readability and the jsdom npm package: npmYarnpnpmnpm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdom
4e9727215e95-1071
npm install @mozilla/readability jsdomyarn add @mozilla/readability jsdompnpm add @mozilla/readability jsdom npm install @mozilla/readability jsdom yarn add @mozilla/readability jsdom pnpm add @mozilla/readability jsdom import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";import { MozillaReadabilityTransformer } from "langchain/document_transformers/mozilla_readability";import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";const loader = new CheerioWebBaseLoader( "https://news.ycombinator.com/item?id=34817881");const docs = await loader.load();const splitter = RecursiveCharacterTextSplitter.fromLanguage("html");const transformer = new MozillaReadabilityTransformer();const sequence = splitter.pipe(transformer);const newDocuments = await sequence.invoke(docs);console.log(newDocuments);/* [ Document { pageContent: 'Hacker News new | past | comments | ask | show | jobs | submit login What Lights\n' + 'the Universe’s Standard Candles?
4e9727215e95-1072
(quantamagazine.org) 75 points by Amorymeltzer\n' + '5 months ago | hide | past | favorite | 6 comments delta_p_delta_x 5 months ago\n' + '| next [–] Astrophysical and cosmological simulations are often insightful.\n' + "They're also very cross-disciplinary; besides the obvious astrophysics, there's\n" + 'networking and sysadmin, parallel computing and algorithm theory (so that the\n' + 'simulation programs are actually fast but still accurate), systems design, and\n' + 'even a bit of graphic design for the visualisations.Some of my favourite\n' + 'simulation projects:- IllustrisTNG:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'that the simulation programs are actually fast but still accurate), systems\n' + 'design, and even a bit of graphic design for the visualisations.Some of my\n' + 'favourite simulation projects:- IllustrisTNG: https://www.tng-project.org/-\n' + 'SWIFT: https://swift.dur.ac.uk/- CO5BOLD:\n' + 'https://www.astro.uu.se/~bf/co5bold_main.html (which produced these animations\n' + 'of a red-giant star: https://www.astro.uu.se/~bf/movie/AGBmovie.html)-\n' + 'AbacusSummit: https://abacussummit.readthedocs.io/en/latest/And I can add the\n' + 'simulations in the article, too.
4e9727215e95-1073
froeb 5 months ago | parent | next [–]\n' + 'Supernova simulations are especially interesting too. I have heard them\n' + 'described as the only time in physics when all 4 of the fundamental forces are\n' + 'important. The explosion can be quite finicky too. If I remember right, you\n' + "can't get supernova to explode", metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'heard them described as the only time in physics when all 4 of the fundamental\n' + 'forces are important. The explosion can be quite finicky too. If I remember\n' + "right, you can't get supernova to explode properly in 1D simulations, only in\n" + 'higher dimensions. This was a mystery until the realization that turbulence is\n' + 'necessary for supernova to trigger--there is no turbulent flow in 1D. andrewflnr\n' + "5 months ago | prev | next [–] Whoa.
4e9727215e95-1074
I didn't know the accretion theory of Ia\n" + 'supernovae was dead, much less that it had been since 2011. andreareina 5 months\n' + 'ago | prev | next [–] This seems to be the paper', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } }, Document { pageContent: 'andreareina 5 months ago | prev | next [–] This seems to be the paper\n' + 'https://academic.oup.com/mnras/article/517/4/5260/6779709 andreareina 5 months\n' + "ago | prev [–] Wouldn't double detonation show up as variance in the brightness?\n" + 'yencabulator 5 months ago | parent [–] Or widening of the peak. If one type Ia\n' + 'supernova goes 1,2,3,2,1, the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3\n' + '0+1=1 Guidelines | FAQ | Lists |', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object]
4e9727215e95-1075
loc: [Object] } }, Document { pageContent: 'the sum of two could go 1+0=1 2+1=3 3+2=5 2+3=5 1+2=3 0+1=1 Guidelines | FAQ |\n' + 'Lists | API | Security | Legal | Apply to YC | Contact Search:', metadata: { source: 'https://news.ycombinator.com/item?id=34817881', loc: [Object] } } ]*/
4e9727215e95-1076
API Reference:CheerioWebBaseLoader from langchain/document_loaders/web/cheerioMozillaReadabilityTransformer from langchain/document_transformers/mozilla_readabilityRecursiveCharacterTextSplitter from langchain/text_splitter You can pass the transformer any arguments accepted by the @mozilla/readability package to customize how it works. OpenAI functions metadata tagger Page Title: OpenAI functions metadata tagger | 🦜️🔗 Langchain Paragraphs: Skip to main content🦜️🔗 LangChainDocsUse casesAPILangSmithPython DocsCTRLKGet startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrationsOpenAI functions metadata taggerOn this pageOpenAI functions metadata taggerIt can often be useful to tag ingested documents with structured metadata, such as the title, tone, or length of a document, to allow for more targeted similarity search later. However, for large numbers of documents, performing this labelling process manually can be tedious.The MetadataTagger document transformer automates this process by extracting metadata from each provided document according to a provided schema. It uses a configurable OpenAI Functions-powered chain under the hood, so if you pass a custom LLM instance, it must be an OpenAI model with functions support.Note: This document transformer works best with complete documents, so it's best to run it first with whole documents before doing any other splitting or processing!Usage​For example, let's say you wanted to index a set of movie reviews.
4e9727215e95-1077
You could initialize the document transformer as follows:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars. ", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring.
4e9727215e95-1078
1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Anonymous', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentThere is an additional createMetadataTagger method that accepts a valid JSON Schema object as well.Customization​You can pass the underlying tagging chain the standard LLMChain arguments in the second options parameter.
4e9727215e95-1079
For example, if you wanted to ask the LLM to focus specific details in the input documents, or extract metadata in a certain style, you could pass in a custom prompt:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";import { PromptTemplate } from "langchain/prompts";const taggingChainTemplate = `Extract the desired information from the following passage.Anonymous critics are actually Roger Ebert.Passage:{input}`;const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }), prompt: PromptTemplate.fromTemplate(taggingChainTemplate),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars.
4e9727215e95-1080
", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring. 1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Roger Ebert', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentPromptTemplate from langchain/promptsPrevious@mozilla/readabilityNextSplit by characterUsageCustomizationCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright © 2023 LangChain, Inc.
4e9727215e95-1081
Get startedIntroductionInstallationQuickstartModulesModel I/​OData connectionDocument loadersDocument transformersIntegrationshtml-to-text@mozilla/readabilityOpenAI functions metadata taggerText splittersText embedding modelsVector storesRetrieversExperimentalCaching embeddingsChainsMemoryAgentsCallbacksModulesGuidesEcosystemAdditional resourcesCommunity navigatorAPI referenceModulesData connectionDocument transformersIntegrationsOpenAI functions metadata taggerOn this pageOpenAI functions metadata taggerIt can often be useful to tag ingested documents with structured metadata, such as the title, tone, or length of a document, to allow for more targeted similarity search later. However, for large numbers of documents, performing this labelling process manually can be tedious.The MetadataTagger document transformer automates this process by extracting metadata from each provided document according to a provided schema. It uses a configurable OpenAI Functions-powered chain under the hood, so if you pass a custom LLM instance, it must be an OpenAI model with functions support.Note: This document transformer works best with complete documents, so it's best to run it first with whole documents before doing any other splitting or processing!Usage​For example, let's say you wanted to index a set of movie reviews.
4e9727215e95-1082
You could initialize the document transformer as follows:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars. ", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring.
4e9727215e95-1083
1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Anonymous', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentThere is an additional createMetadataTagger method that accepts a valid JSON Schema object as well.Customization​You can pass the underlying tagging chain the standard LLMChain arguments in the second options parameter.
4e9727215e95-1084
For example, if you wanted to ask the LLM to focus specific details in the input documents, or extract metadata in a certain style, you could pass in a custom prompt:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";import { PromptTemplate } from "langchain/prompts";const taggingChainTemplate = `Extract the desired information from the following passage.Anonymous critics are actually Roger Ebert.Passage:{input}`;const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }), prompt: PromptTemplate.fromTemplate(taggingChainTemplate),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars.
4e9727215e95-1085
", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring. 1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Roger Ebert', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentPromptTemplate from langchain/promptsPrevious@mozilla/readabilityNextSplit by characterUsageCustomization
4e9727215e95-1086
ModulesData connectionDocument transformersIntegrationsOpenAI functions metadata taggerOn this pageOpenAI functions metadata taggerIt can often be useful to tag ingested documents with structured metadata, such as the title, tone, or length of a document, to allow for more targeted similarity search later. However, for large numbers of documents, performing this labelling process manually can be tedious.The MetadataTagger document transformer automates this process by extracting metadata from each provided document according to a provided schema. It uses a configurable OpenAI Functions-powered chain under the hood, so if you pass a custom LLM instance, it must be an OpenAI model with functions support.Note: This document transformer works best with complete documents, so it's best to run it first with whole documents before doing any other splitting or processing!Usage​For example, let's say you wanted to index a set of movie reviews.
4e9727215e95-1087
You could initialize the document transformer as follows:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars. ", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring.
4e9727215e95-1088
1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Anonymous', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentThere is an additional createMetadataTagger method that accepts a valid JSON Schema object as well.Customization​You can pass the underlying tagging chain the standard LLMChain arguments in the second options parameter.
4e9727215e95-1089
For example, if you wanted to ask the LLM to focus specific details in the input documents, or extract metadata in a certain style, you could pass in a custom prompt:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";import { PromptTemplate } from "langchain/prompts";const taggingChainTemplate = `Extract the desired information from the following passage.Anonymous critics are actually Roger Ebert.Passage:{input}`;const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }), prompt: PromptTemplate.fromTemplate(taggingChainTemplate),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars.
4e9727215e95-1090
", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring. 1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Roger Ebert', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentPromptTemplate from langchain/promptsPrevious@mozilla/readabilityNextSplit by characterUsageCustomization
4e9727215e95-1091
ModulesData connectionDocument transformersIntegrationsOpenAI functions metadata taggerOn this pageOpenAI functions metadata taggerIt can often be useful to tag ingested documents with structured metadata, such as the title, tone, or length of a document, to allow for more targeted similarity search later. However, for large numbers of documents, performing this labelling process manually can be tedious.The MetadataTagger document transformer automates this process by extracting metadata from each provided document according to a provided schema. It uses a configurable OpenAI Functions-powered chain under the hood, so if you pass a custom LLM instance, it must be an OpenAI model with functions support.Note: This document transformer works best with complete documents, so it's best to run it first with whole documents before doing any other splitting or processing!Usage​For example, let's say you wanted to index a set of movie reviews.
4e9727215e95-1092
You could initialize the document transformer as follows:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars. ", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring.
4e9727215e95-1093
1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Anonymous', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentThere is an additional createMetadataTagger method that accepts a valid JSON Schema object as well.Customization​You can pass the underlying tagging chain the standard LLMChain arguments in the second options parameter.
4e9727215e95-1094
For example, if you wanted to ask the LLM to focus specific details in the input documents, or extract metadata in a certain style, you could pass in a custom prompt:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";import { PromptTemplate } from "langchain/prompts";const taggingChainTemplate = `Extract the desired information from the following passage.Anonymous critics are actually Roger Ebert.Passage:{input}`;const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }), prompt: PromptTemplate.fromTemplate(taggingChainTemplate),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars.
4e9727215e95-1095
", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring. 1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Roger Ebert', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentPromptTemplate from langchain/promptsPrevious@mozilla/readabilityNextSplit by character
4e9727215e95-1096
OpenAI functions metadata taggerIt can often be useful to tag ingested documents with structured metadata, such as the title, tone, or length of a document, to allow for more targeted similarity search later. However, for large numbers of documents, performing this labelling process manually can be tedious.The MetadataTagger document transformer automates this process by extracting metadata from each provided document according to a provided schema. It uses a configurable OpenAI Functions-powered chain under the hood, so if you pass a custom LLM instance, it must be an OpenAI model with functions support.Note: This document transformer works best with complete documents, so it's best to run it first with whole documents before doing any other splitting or processing!Usage​For example, let's say you wanted to index a set of movie reviews.
4e9727215e95-1097
You could initialize the document transformer as follows:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars. ", metadata: { reliable: false }, }),];const taggedDocuments = await metadataTagger.transformDocuments(documents);console.log(taggedDocuments);/* [ Document { pageContent: 'Review of The Bee Movie\n' + 'By Roger Ebert\n' + 'This is the greatest movie ever made. 4 out of 5 stars. ', metadata: { movie_title: 'The Bee Movie', critic: 'Roger Ebert', tone: 'positive', rating: 4 } }, Document { pageContent: 'Review of The Godfather\n' + 'By Anonymous\n' + '\n' + 'This movie was super boring.
4e9727215e95-1098
1 out of 5 stars. ', metadata: { movie_title: 'The Godfather', critic: 'Anonymous', tone: 'negative', rating: 1, reliable: false } } ]*/API Reference:createMetadataTaggerFromZod from langchain/document_transformers/openai_functionsChatOpenAI from langchain/chat_models/openaiDocument from langchain/documentThere is an additional createMetadataTagger method that accepts a valid JSON Schema object as well.Customization​You can pass the underlying tagging chain the standard LLMChain arguments in the second options parameter.
4e9727215e95-1099
For example, if you wanted to ask the LLM to focus specific details in the input documents, or extract metadata in a certain style, you could pass in a custom prompt:import { z } from "zod";import { createMetadataTaggerFromZod } from "langchain/document_transformers/openai_functions";import { ChatOpenAI } from "langchain/chat_models/openai";import { Document } from "langchain/document";import { PromptTemplate } from "langchain/prompts";const taggingChainTemplate = `Extract the desired information from the following passage.Anonymous critics are actually Roger Ebert.Passage:{input}`;const zodSchema = z.object({ movie_title: z.string(), critic: z.string(), tone: z.enum(["positive", "negative"]), rating: z .optional(z.number()) .describe("The number of stars the critic rated the movie"),});const metadataTagger = createMetadataTaggerFromZod(zodSchema, { llm: new ChatOpenAI({ modelName: "gpt-3.5-turbo" }), prompt: PromptTemplate.fromTemplate(taggingChainTemplate),});const documents = [ new Document({ pageContent: "Review of The Bee Movie\nBy Roger Ebert\nThis is the greatest movie ever made. 4 out of 5 stars. ", }), new Document({ pageContent: "Review of The Godfather\nBy Anonymous\n\nThis movie was super boring. 1 out of 5 stars.