Sycamore Documentation
repository·main·Indexed 20 days ago
https://github.com/aryn-ai/sycamoreAn 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.
What's inside Sycamore
- Sycamore Query provides tools for querying unstructured data sources using natural language. It leverages Large Language Models (LLMs) to translate natural language queries into executable query plans that run on the Sycamore engine.
Build LLM query-powered pipelines with Sycamore Query
mainThe
sycamore.querypackage provides the tools necessary to construct sophisticated pipelines driven by Large Language Model (LLM) queries. It is organized into three primary functional areas:- Client (
sycamore.query.client): The entry point for interacting with the query system. - Planner (
sycamore.query.planner): Responsible for interpreting queries and determining the necessary execution steps. - Logical Plan (
sycamore.query.logical_plan): Defines the structured representation of the operations required to fulfill a query.
- Client (
What is a DocSet?
mainADocSetis 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.What is Sycamore and how does it work?
mainSycamore 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.
Identify Execution Categories: Scans, Transforms, and Writes
mainExecution 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.
How Sycamore Query plans work
mainA Sycamore Query plan is an instance of the
LogicalPlanclass. It represents a tree of operators (nodes) that process data. Operators can be standard data-processing steps (likeTopK,count,sort,group-by) or LLM-powered steps (likeLlmFilterorSummarizeData).Users can interact with plans in two ways:
- Automatic Generation: Use
SycamoreQueryClient.query()to let an LLM generate a plan from natural language, orSycamoreQueryClient.generate_plan()to inspect the plan without running it. - Manual Construction: Build a
LogicalPlandirectly in code and execute it usingSycamoreQueryClient.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) } }- Automatic Generation: Use
Use the Embed Transform to generate embeddings
mainThe
Embedtransform generates embeddings for yourDocumentsorElementsand stores them in a specialembeddingproperty on each document. To use it, call the.embed(embedder)method on aDocSet, passing in anembedderobject that encapsulates a specific embedding model and its parameters.embedded_doc_set = docset.embed(embedder)Understand the Sycamore Data Ingestion and Preparation pipeline
mainThe ingestion pipeline consists of two main stages: crawling and importing.
- Crawlers: Containers that fetch data from sources like Amazon S3 buckets or websites. They are optimized to only download new or updated data.
- 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.
Understand Lazy Execution in Sycamore
mainDocSet 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.Use the merge transform for chunking
mainThe
mergetransform is used to combine individual elements into larger 'chunks' (a process also known as 'chunking'). To use it, you must provide amergerargument to thedocset.merge()method. Themergerdefines the logic for which elements should be combined and how they should be merged. For detailed implementation details, refer to themerge_elementsAPI documentation.# General pattern merged_docset = docset.merge(merger=merger_instance)Concept: Processors vs Pipelines in Remote Processor Service
mainThe Remote Processor Service uses two levels of abstraction to manage search post-processing:
- Processor: A single unit of processing logic.
- 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.
What are Remote Search Processors in Sycamore
mainSycamore 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 tostdout, which is useful for inspecting query behavior.