MCPcopy Create free account
hub / github.com/tmc/langchaingo / Load

Method Load

documentloaders/html.go:27–49  ·  view source on GitHub ↗

Load reads from the io.Reader and returns a single document with the data.

(_ context.Context)

Source from the content-addressed store, hash-verified

25
26// Load reads from the io.Reader and returns a single document with the data.
27func (h HTML) Load(_ context.Context) ([]schema.Document, error) {
28 doc, err := goquery.NewDocumentFromReader(h.r)
29 if err != nil {
30 return nil, err
31 }
32
33 var sel *goquery.Selection
34 if doc.Has("body") != nil {
35 sel = doc.Find("body").Contents()
36 } else {
37 sel = doc.Contents()
38 }
39
40 sanitized := bluemonday.UGCPolicy().Sanitize(sel.Text())
41 pagecontent := strings.TrimSpace(sanitized)
42
43 return []schema.Document{
44 {
45 PageContent: pagecontent,
46 Metadata: map[string]any{},
47 },
48 }, nil
49}
50
51// LoadAndSplit reads text data from the io.Reader and splits it into multiple
52// documents using a text splitter.

Callers 2

LoadAndSplitMethod · 0.95
TestHTMLLoaderFunction · 0.95

Calls

no outgoing calls

Tested by 1

TestHTMLLoaderFunction · 0.76