npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

li-sa-readers-and-parsers

v1.0.1

Published

Standalone readers and parsers from LlamaIndex

Downloads

33

Readme

LlamaIndex Standalone Readers and Parsers

This is a small package that includes most of the basic file readers and parsers/splitters from LlamaIndex. LlamaIndex is great, but if you only want the simple RAG content splitters, well this package is for you.

Example Usage

import { MarkdownReader, MarkdownNodeParser } from "li-sa-readers-and-parsers"

const reader = new MarkdownReader()
const parser = new MarkdownNodeParser()

const docs = await reader.loadData("./README.md")
const splits = await parser.getNodesFromDocuments(docs)

for (split of splits) { 
    console.log(split.getContent()) 
}

Readers

The file readers included in this package are:

  • PapaCSVReader
  • DocxReader
  • HTMLReader
  • ImageReader
  • MarkdownReader
  • PDFReader
  • TextFileReader
  • JSONReader

There is a reader called SimpleFileReader that uses the file extension of the passed in file to automatically pick the right reader to use. There is a SimpleDirectoryReader that reads all of the files in a directory and automatically picks the right readers to use to read each file, and is documented here.

There is another reader called LlamaParseReader that uses a hosted service to parse uploaded files, and supports a great many file types. Read about it here.

Another reader called SimpleMongoReader can use a passed-in MongoDB client and some filtering directives to read content from a Mongo database.

Parsers

The parsers included in this package are:

  • MarkdownNodeParser
  • MetadataAwareTextSplitter
  • NodeParser
  • SentenceSplitter
  • SentenceWindowNodeParser
  • SimpleNodeParser
  • TextSplitter
  • splitByChar
  • splitByPhraseRegex
  • splitByRegex
  • splitBySentenceTokenizer
  • splitBySep

Most of these parsers are documented here

The Document Object

File readers and parsers return content in the form of Documents. A Document is a subclass of a TextNode. These are described here. Here is a cheat-sheet:

TextNode
  constructor({ text, textTemplate, startCharIdx, endCharIdx, metadataSeparator })
  generateHash() -> str
  getContent() -> str
  setContent(str)
  getText() -> str
  type() -> "TEXT"
  getNodeInfo() -> {start: , end: }

Document extends TextNode
  type() -> "DOCUMENT"

After you have "parsed" a file into nodes, you can do something like:

const metadata = {
    loc: split.getNodeInfo(),
    ...split.metadata
}
console.log(JSON.stringify(metadata, null, 2))
{
    "loc": {
        "start": 4,
        "end": 361,
    },
    "file_path": "/mnt/data/files/README.md",
    "file_name": "README.md"
}

Dependencies

Some of the readers require external dependencies to operate. These dependencies are listed in package.json under "optionalDependencies". These will be installed when you "npm install" this package. If you do not need certain readers and you want to save space, you can uninstall the dependencies you do not want. The readers that require external dependencies dynamically load them only when they are used.