datapizza-ai

repository·main·Indexed 25 days ago

https://github.com/datapizza-labs/datapizza-ai

A high-performance, API-first Python framework for building reliable Generative AI solutions, such as agents and RAG systems. It features a vendor-agnostic design with support for BedrockClient, OpenAILikeClient (compatible with Ollama, Together AI, and OpenRouter), and various embedders including Google and Mistral AI. The framework emphasizes observability and composability, providing tools for conversation memory, function calling, asynchronous streaming, and structured outputs via Pydantic.

Tokens
60.9K
Snippets
187
Records
244
Agent score
80%

What's inside datapizza-ai

  1. FastEmbedder features and capabilities

    main

    The FastEmbedder provides the following capabilities:

    • Efficient Sparse Embeddings: Uses FastEmbed for high-performance sparse text embeddings.
    • Local Execution: Models run locally on your machine; no external API calls are required.
    • Configurable Caching: Supports a configurable model caching directory.
    • Custom Naming: Allows defining a custom embedding_name.
    • Memory Efficiency: Uses a sparse embedding format to reduce memory footprint.
    • Async Support: Provides both synchronous and asynchronous embedding methods.
  2. GoogleEmbedder features and capabilities

    main

    The GoogleEmbedder provides the following capabilities:

    • Model Support: Works with Google's Gemini embedding models.
    • Batching: Handles both single text strings and lists of texts for batch embedding.
    • Async Support: Provides a_embed() for asynchronous workflows.
    • Management: Handles automatic client initialization and management using Google's Generative AI SDK.
  3. What is a Treebuilder?

    main

    Treebuilders are pipeline components designed to construct hierarchical tree structures composed of Node objects from various types of content. They transform flat or unstructured data (such as articles, reports, or manuals) into organized, nested representations. This facilitates better semantic processing and understanding of the content.

    Key capabilities include:

    • Semantic Organization: Uses language models to understand content structure.
    • Metadata Extraction: Adds tagging and metadata during the creation process.
    • Configurability: Supports configurable tree depth and structure rules.
    • Processing Modes: Supports both synchronous and asynchronous processing.
  4. Use TextParser to parse text into a hierarchical structure

    main

    The TextParser module converts plain text into a structured hierarchy of nodes. It splits text into paragraphs (based on double newlines) and then breaks those paragraphs into sentences using regex patterns.

    This creates a three-level hierarchy:

    1. DOCUMENT: The root container.
    2. PARAGRAPH: Intermediate nodes representing paragraphs.
    3. SENTENCE: Leaf nodes containing the actual text content.

    Each paragraph and sentence node includes index metadata to preserve the original structure.

    from datapizza.modules.parsers.text_parser import TextParser
    
    parser = TextParser()
    document_node = parser.parse("Your text content here", metadata={"source": "example"})
  5. Features of NodeSplitter

    main

    The NodeSplitter provides several key capabilities for document processing:

    • Maintains Node structure: Preserves the object structure and hierarchy of the original document.
    • Metadata Preservation: Keeps metadata from the original nodes attached to the resulting chunks.
    • Boundary Respect: Attempts to respect existing node boundaries during the splitting process.
    • Flexible Chunking: Supports both structure-preserving and flattened chunking modes.
    • Nested Relationship Handling: Intelligently manages nested node relationships.
  6. Manage conversation history with the Memory class

    main

    The Memory class is used to store and manage the sequence of exchanges in a conversation. This enables the AI to reference previous turns.

    To maintain an accurate history, use the following pattern:

    1. Retrieve Context: Pass the Memory object to client.invoke(..., memory=memory) to include history in the prompt.
    2. Record User Input: Use memory.add_turn(TextBlock(content=user_input), role=ROLE.USER) to save the user's message.
    3. Record Assistant Response: Use memory.add_turn(response.content, role=ROLE.ASSISTANT) to save the AI's reply.

    Note: User turns typically require wrapping the content in a TextBlock object.

  7. Configure reasoning with thinking_config

    main

    Gemini models support explicit reasoning. By setting include_thoughts=True in the thinking_config dictionary, the response will include a thoughts attribute containing the model's reasoning process.

    Gemini 2.5 (Budget-based)

    Use thinking_budget to specify a token budget for reasoning.

    Gemini 3 (Level-based)

    Use thinking_level to set the reasoning depth. Supported values are "low" or "high".

    # Gemini 2.5 Example
    response = client.invoke(
        input="Explain step by step why the sky is blue.",
        thinking_config={
            "thinking_budget": 1024,
            "include_thoughts": True,
        },
    )
    print("Thoughts:", response.thoughts)
    
    # Gemini 3 Example
    response = client_3.invoke(
        input="Design a simple movie recommendation algorithm.",
        thinking_config={
            "thinking_level": "high",  # "low" | "high"
            "include_thoughts": True,
        },
    )
    print("Thoughts:", response.thoughts)
  8. What are Rewriters in Datapizza AI

    main
    Rewriters are pipeline components designed to transform and rewrite text content using language models. They allow you to modify the style, format, tone, or structure of text while preserving the underlying meaning and essential information. They are useful for tasks such as summarization, style changes, and format conversion. Rewriters support both synchronous and asynchronous processing and can be configured with custom instructions and tool-calling capabilities.
  9. What are Parsers in Datapizza AI

    main

    Parsers are pipeline components responsible for converting documents into structured, hierarchical Node representations. They extract text, layout information, and metadata from various document formats to create tree-like data structures.

    Key Requirement: Every parser must return a Node object. If you implement a custom parser that returns a different type (such as raw plain text), you must use a TreeBuilder to convert that output into a Node structure before proceeding with the pipeline.

  10. What are Rerankers and how do they work?

    main
    Rerankers are pipeline components designed to reorder and score retrieved content based on its relevance to a specific query. They are typically used after an initial retrieval step (like a vector search) to apply more sophisticated ranking algorithms. This process helps surface the most relevant content for user queries by filtering or re-prioritizing the results provided by the initial retriever.
  11. How the Ingestion Pipeline works

    main

    The IngestionPipeline is a workflow engine designed to process documents by chaining together various processing steps.

    Core Concepts

    • Components: Individual processing steps (e.g., parsers, splitters, embedders) that inherit from datapizza.core.models.PipelineComponent. They implement a _run method and are executed sequentially via their __call__ method in the order they are provided in the modules list.
    • Nodes: The fundamental data unit passed between components. A node typically contains a chunk of text, associated metadata, and embeddings.
    • Vector Store: An optional component at the end of the pipeline responsible for storing the final nodes and their embeddings for retrieval.

    Typical Workflow

    1. Parsers: Convert raw files (PDF, DOCX) into Node objects.
    2. Captioners: (Optional) Use LLMs to add textual descriptions to image or table nodes.
    3. Splitters: Divide nodes into smaller, manageable chunks.
    4. Embedders: Generate semantic embeddings for the chunks.
    5. Vector Stores: Persist the nodes and embeddings.