Generative & RagRag With Generative Search

RAG With Generative Search

Unbody gives you various ways to perform RAG - from generating insights from single documents to analyzing multiple sources at once.

Generate from every single document

When you need to generate a result for each object based on a single prompt, use the .generate.fromOne() method. For example, you can create summaries from your textDocuments by referencing any document property using {propertyName} syntax.

const {
  data: { generate }
} = await unbody.get
                .textDocument
                .generate.fromOne("Summarize this in max 100 words: {text}")
                .select("title", "originalName")
                .exec();

Generate from every single document with options

You might want to adjust the maxTokens, creativity level, or use a specific model for your generated content. Use generative search options to fine-tune these parameters.

const {
  data: { generate }
} = await unbody.get
                .textDocument
                .where({ mimeType: "text/markdown" })
                .generate.fromOne({
                  prompt: "Create a short report for these: {text}",
                  options: {
                    model: "gpt-4",
                    topP: 0.7,
                    maxTokens: 1000,
                    temperature: 0.7,
                    presencePenalty: 0,
                    frequencyPenalty: 0
                  }
                })
                .select("originalName")
                .exec();

Generate from multiple documents

When you need to generate from multiple documents together and get a grouped result, use the .generate.fromMany() method. This lets you combine specific fields from all your sources to create a single generative result.

const {
  data: { generate }
} = await unbody.get
                .textDocument
                .generate.fromMany("Create a 100 words summary:", ["text", "title"])
                .select("title", "originalName")
                .exec();

Generate from multiple documents with options

Sometimes you want more control over your multi-document generation. Using fromMany with options lets you better control the output.

const {
  data: { generate }
} = await unbody.get
                .textDocument
                .where({ mimeType: "text/markdown" })
                .generate.fromMany({
                  task: "Write a short report based on these topics:",
                  properties: ["title", "text", "toc", "authors"],
                  options: {
                    model: "gpt-4",
                    topP: 0.7,
                    maxTokens: 1000,
                    temperature: 0.7,
                    presencePenalty: 0,
                    frequencyPenalty: 0
                  }
                })
                .select("originalName", "title")
                .exec();

Learn more about generative search in detail in our Generative Search Guide.

©2024 Unbody