Sycamore Documentation

repository·main·Indexed 20 days ago

https://github.com/aryn-ai/sycamore

An open-source, AI-powered document processing engine for ETL, RAG, and analytics on unstructured data. Sycamore uses Aryn DocParse to partition complex documents and provides a scalable DocSet abstraction for transforming and loading data into vector databases. It includes integrations for OpenSearch, Jupyter, and BigQuery, as well as a Remote Processor Service for search post-processing.

Tokens
117.9K
Snippets
382
Records
487
Agent score
69%

What's inside Sycamore

  1. Build LLM query-powered pipelines with Sycamore Query

    main

    The sycamore.query package provides the tools necessary to construct sophisticated pipelines driven by Large Language Model (LLM) queries. It is organized into three primary functional areas:

    1. Client (sycamore.query.client): The entry point for interacting with the query system.
    2. Planner (sycamore.query.planner): Responsible for interpreting queries and determining the necessary execution steps.
    3. Logical Plan (sycamore.query.logical_plan): Defines the structured representation of the operations required to fulfill a query.
  2. What is a DocSet?

    main
    A DocSet is the core abstraction in the Sycamore framework used for scalable and reliable document processing. It allows you to transform, manipulate, and enrich unstructured documents using a functional programming approach. DocSets encapsulate scalable data processing techniques, removing the heavy lifting required to reliably load document chunks into downstream databases.
  3. What is Sycamore and how does it work?

    main

    Sycamore is a document processing engine designed for complex unstructured data (documents, presentations, transcripts, embedded tables, etc.).

    It uses a declarative dataflow abstraction called a DocSet to manipulate collections of unstructured documents. This abstraction is similar in style to Apache Spark or Pandas but is optimized for document collections.

    Core Capabilities:

    • Data Transformation: Use LLM-powered transforms for extracting, enriching, summarizing, and cleaning data.
    • Vector ETL: Generate vector embeddings and load them into vector databases or search engines (e.g., Pinecone, OpenSearch, Weaviate, Elasticsearch, Qdrant, etc.).
    • Lineage: Maintain document lineage throughout the processing pipeline using the DocSet abstraction.
    • Plug-and-Play LLMs: Use different LLMs for specific tasks like entity extraction, embedding, or post-processing.
  4. Identify Execution Categories: Scans, Transforms, and Writes

    main

    Execution operations in Sycamore are categorized into three primary types:

    • Scans: Responsible for reading data from various data sources.
    • Transforms: (Logic for data manipulation/transformation).
    • Writes: Responsible for persisting data to destinations.
  5. How Sycamore Query plans work

    main

    A Sycamore Query plan is an instance of the LogicalPlan class. It represents a tree of operators (nodes) that process data. Operators can be standard data-processing steps (like TopK, count, sort, group-by) or LLM-powered steps (like LlmFilter or SummarizeData).

    Users can interact with plans in two ways:

    1. Automatic Generation: Use SycamoreQueryClient.query() to let an LLM generate a plan from natural language, or SycamoreQueryClient.generate_plan() to inspect the plan without running it.
    2. Manual Construction: Build a LogicalPlan directly in code and execute it using SycamoreQueryClient.run_plan().
    # Example of what a generated plan structure looks like
    {
        "nodes": {
            "0": QueryDatabase(
                        node_id=0,
                        description="Get all the incident reports with substantial aircraft damage",
                        input=None,
                        index="const_ntsb",
                        query={"match": {"properties.entity.aircraftDamage": "Substantial"}}
                     ),
            "1": TopK(
                        node_id=1,
                        description="Get the breakdown of aircraft types",
                        input=[0],
                        field="properties.entity.aircraft",
                        primary_field="properties.entity.accidentNumber",
                        K=100,
                        descending=False)
        }
    }
  6. Use the Embed Transform to generate embeddings

    main

    The Embed transform generates embeddings for your Documents or Elements and stores them in a special embedding property on each document. To use it, call the .embed(embedder) method on a DocSet, passing in an embedder object that encapsulates a specific embedding model and its parameters.

    embedded_doc_set = docset.embed(embedder)
  7. Understand the Sycamore Data Ingestion and Preparation pipeline

    main

    The ingestion pipeline consists of two main stages: crawling and importing.

    1. Crawlers: Containers that fetch data from sources like Amazon S3 buckets or websites. They are optimized to only download new or updated data.
    2. Importer: A container that runs data preparation workloads on Ray (an open-source framework for scaling Python workloads). The Importer performs:
      • Data cleaning and information extraction.
      • Enrichment and summarization.
      • Generation of vector embeddings.
      • Loading prepared data into Sycamore's vector and keyword indexes.

    Note: The Importer supports Generative AI User Defined Functions (UDFs) with various LLMs and vector embedding models. It includes error handling to manage Out-of-Memory (OOM) issues and prevent specific files from failing the entire Sycamore script.

  8. Understand Lazy Execution in Sycamore

    main
    DocSet evaluation in Sycamore is lazy. This means that calling transformation methods (like .partition() or .embed()) does not immediately execute the work. The transformations are only triggered when an action requires the data, such as calling .show() to inspect results or .write() to save to a target. This allows Sycamore to optimize the execution plan before running the workload on the Ray backend.
  9. Use the merge transform for chunking

    main

    The merge transform is used to combine individual elements into larger 'chunks' (a process also known as 'chunking'). To use it, you must provide a merger argument to the docset.merge() method. The merger defines the logic for which elements should be combined and how they should be merged. For detailed implementation details, refer to the merge_elements API documentation.

    # General pattern
    merged_docset = docset.merge(merger=merger_instance)
  10. Concept: Processors vs Pipelines in Remote Processor Service

    main

    The Remote Processor Service uses two levels of abstraction to manage search post-processing:

    1. Processor: A single unit of processing logic.
    2. Pipeline: A sequence (string) of one or more processors.

    The Workflow: OpenSearch uses a Remote Search Processor (a plugin) to make an RPC call to the service. This RPC call targets a specific Pipeline endpoint in the service. The service then executes the string of Processors defined in that pipeline.

    Essentially, you have an OpenSearch search pipeline that triggers a remote search pipeline.

  11. What are Remote Search Processors in Sycamore

    main

    Sycamore extends OpenSearch capabilities by providing custom search processors via a remote-processor. Instead of running locally within OpenSearch, these processors make a network call to a Sycamore service hosting the logic. This allows Sycamore to provide advanced processing features like result de-duplication and debugging tools that are not native to OpenSearch.

    Available Sycamore remote processors include:

    • dedup: De-duplicates search results based on similarity.
    • debug: Prints the search response to stdout, which is useful for inspecting query behavior.