diff --git a/apps/docs/docs/modules/index.md b/apps/docs/docs/modules/index.md index a2eba28d5f2a59813d0f179428147a205b61c65e..9a4ade520089ec4e187b533028c4d33f172448f7 100644 --- a/apps/docs/docs/modules/index.md +++ b/apps/docs/docs/modules/index.md @@ -18,14 +18,14 @@ LlamaIndex.TS offers several core modules, seperated into high-level modules for ## Low Level Module -- [**SimplePrompt**](./low_level/simple_prompt.md): A simple standardized function call definition that takes in inputs and puts them in a prebuilt template. - - [**LLM**](./low_level/llm.md): The LLM class is a unified interface over a large language model provider such as OpenAI GPT-4, Anthropic Claude, or Meta LLaMA. You can subclass it to write a connector to your own large language model. - [**Embedding**](./low_level/embedding.md): An embedding is represented as a vector of floating point numbers. OpenAI's text-embedding-ada-002 is our default embedding model and each embedding it generates consists of 1,536 floating point numbers. Another popular embedding model is BERT which uses 768 floating point numbers to represent each Node. We provide a number of utilities to work with embeddings including 3 similarity calculation options and Maximum Marginal Relevance -- [**TextSplitter**](./low_level/text_splitter.md): Text splitting strategies are incredibly important to the overall efficacy of the embedding search. Currently, while we do have a default, there's no one size fits all solution. Depending on the source documents, you may want to use different splitting sizes and strategies. Currently we support spliltting by fixed size, splitting by fixed size with overlapping sections, splitting by sentence, and splitting by paragraph. +- [**TextSplitter/NodeParser**](./low_level/text_splitter.md): Text splitting strategies are incredibly important to the overall efficacy of the embedding search. Currently, while we do have a default, there's no one size fits all solution. Depending on the source documents, you may want to use different splitting sizes and strategies. Currently we support spliltting by fixed size, splitting by fixed size with overlapping sections, splitting by sentence, and splitting by paragraph. The text splitter is used by the NodeParser when splitting `Document`s into `Node`s. - [**Retriever**](./low_level/retriever.md): The Retriever is what actually chooses the Nodes to retrieve from the index. Here, you may wish to try retrieving more or fewer Nodes per query, changing your similarity function, or creating your own retriever for each individual use case in your application. For example, you may wish to have a separate retriever for code content vs. text content. +- [**ResponseSynthesizer**](./low_level/response_synthesizer.md): The ResponseSynthesizer is responsible for taking a query string, and using a list of `Node`s to generate a response. This can take many forms, like iterating over all the context and refining an answer, or building a tree of summaries and returning the root summary. + - [**Storage**](./low_level/storage.md): At some point you're going to want to store your indexes, data and vectors instead of re-running the embedding models every time. IndexStore, DocStore, VectorStore, and KVStore are abstractions that let you do that. Combined, they form the StorageContext. Currently, we allow you to persist your embeddings in files on the filesystem (or a virtual in memory file system), but we are also actively adding integrations to Vector Databases. diff --git a/apps/docs/docs/modules/low_level/node_parser.md b/apps/docs/docs/modules/low_level/node_parser.md new file mode 100644 index 0000000000000000000000000000000000000000..dae6a5d71aecfad1006be1f19cc87c99c7f65f3a --- /dev/null +++ b/apps/docs/docs/modules/low_level/node_parser.md @@ -0,0 +1,31 @@ +--- +sidebar_position: 3 +--- + +# NodeParser + +The `NodeParser` in LlamaIndex is responbile for splitting `Document` objects into more manageable `Node` objects. When you call `.fromDocuments()`, the `NodeParser` from the `ServiceContext` is used to do this automatically for you. Alternatively, you can use it to split documents ahead of time. + +```typescript +import { + Document, + SimpleNodeParser, +} from "llamaindex"; + +const nodeParser = new SimpleNodeParser(); +const nodes = nodeParser.getNodesFromDocuments([ + new Document({ text: "I am 10 years old. John is 20 years old." }), +]); +``` + +## TextSplitter + +The underlying text splitter will split text by sentences. It can also be used as a standalone module for splitting raw text. + +```typescript +import { SentenceSplitter } from "llamaindex"; + +const splitter = new SentenceSplitter({ chunkSize: 1, }); + +const textSplits = splitter.splitText("Hello World"); +``` diff --git a/apps/docs/docs/modules/low_level/response_synthesizer.md b/apps/docs/docs/modules/low_level/response_synthesizer.md new file mode 100644 index 0000000000000000000000000000000000000000..e8b471b942f735f9f71dd42efe8f24e43abac5bf --- /dev/null +++ b/apps/docs/docs/modules/low_level/response_synthesizer.md @@ -0,0 +1,48 @@ +--- +sidebar_position: 6 +--- + +# ResponseSynthesizer + +The ResponseSynthesizer is responsible for sending the query, nodes, and prompt templates to the LLM to generate a response. There are a few key modes for generating a response: + +- `Refine`: "create and refine" an answer by sequentially going through each retrieved text chunk. + This makes a separate LLM call per Node. Good for more detailed answers. +- `CompactAndRefine` (default): "compact" the prompt during each LLM call by stuffing as + many text chunks that can fit within the maximum prompt size. If there are + too many chunks to stuff in one prompt, "create and refine" an answer by going through + multiple compact prompts. The same as `refine`, but should result in less LLM calls. +- `TreeSummarize`: Given a set of text chunks and the query, recursively construct a tree + and return the root node as the response. Good for summarization purposes. +- `SimpleResponseBuilder`: Given a set of text chunks and the query, apply the query to each text + chunk while accumulating the responses into an array. Returns a concatenated string of all + responses. Good for when you need to run the same query separately against each text + chunk. + +```typescript +import { + TextNode, + NodeWithScore, + ResponseSynthesizer, + CompactAndRefine +} from "llamaindex"; + +const responseSynthesizer = new ResponseSynthesizer(); + +const nodesWithScore: NodeWithScore[] = [ + { + node: new TextNode({ text: "I am 10 years old." }), + score: 1, + }, + { + node: new TextNode({ text: "John is 20 years old." }), + score: 0.5, + }, +]; + +const response = await responseSynthesizer.asynthesize( + "What age am I?", + nodesWithScore +); +console.log(response.response); +``` \ No newline at end of file diff --git a/apps/docs/docs/modules/low_level/retriever.md b/apps/docs/docs/modules/low_level/retriever.md index 2976ae2e0fc9978492f8c1cdc397ec42f6e8d68f..55eb7a2a5311ee4409ab53bdfaa424ab98eafef6 100644 --- a/apps/docs/docs/modules/low_level/retriever.md +++ b/apps/docs/docs/modules/low_level/retriever.md @@ -11,5 +11,5 @@ const retriever = vector_index.asRetriever() retriever.similarityTopK = 3; // Fetch nodes! -const nodes = await retriever.aretrieve("query string"); +const nodesWithScore = await retriever.aretrieve("query string"); ``` diff --git a/apps/docs/docs/modules/low_level/simple_prompt.md b/apps/docs/docs/modules/low_level/simple_prompt.md deleted file mode 100644 index e10aed1041adb85291bd6eb3c48ad111e72695d6..0000000000000000000000000000000000000000 --- a/apps/docs/docs/modules/low_level/simple_prompt.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -sidebar_position: 4 ---- - -# SimplePrompt - -Prompts are the basic inputs to an LLM. These can contain variables that get filled in later, or just plain text that is sent as-is to a model. diff --git a/apps/docs/docs/modules/low_level/storage.md b/apps/docs/docs/modules/low_level/storage.md index b7423946e83b06d5e85d0b07e00e51e0d38e3518..45dfff552a472650659a365a7b5d3bb0e7ec4303 100644 --- a/apps/docs/docs/modules/low_level/storage.md +++ b/apps/docs/docs/modules/low_level/storage.md @@ -1,5 +1,5 @@ --- -sidebar_position: 6 +sidebar_position: 7 --- # Storage diff --git a/apps/docs/docs/modules/low_level/text_splitter.md b/apps/docs/docs/modules/low_level/text_splitter.md deleted file mode 100644 index 0375e03ffd9081c2016d54a1864e3d9cbb53788f..0000000000000000000000000000000000000000 --- a/apps/docs/docs/modules/low_level/text_splitter.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -sidebar_position: 3 ---- - -# TextSplitter - -Todo: Talk about text splitter. Alternatively, replace this with node parser? Or combine them?