← Back to 004 foundation

03 gemini

Documentation for 03_gemini from the Ds ex repository.

Excellent. Based on the comprehensive review and my proposed specification for the DSPex Foundation, I will now filter the exhaustive lists of libraries and discussions, selecting only those components and ideas that directly map to the plan.

This curated list will detail which libraries we will use, their specific role within the DSPex Foundation architecture, and whether they belong in the generic foundation hex package or the more specific DSPex application layer.


Curated Components for the DSPex Foundation

This specification refines our plan by selecting specific Elixir libraries to implement the core components of the DSPex Foundation.

Boundary Definition

  • foundation (Hex Package): Will remain a lean, generic infrastructure library. It will not include any AI-specific or heavy ML dependencies like Nx. The enhancements proposed in “Foundation Enhancement Series IV” (Service Mesh, Advanced Pipelines, etc.) are excellent long-term goals for this package but are considered out-of-scope for the immediate DSPex build-out, which will leverage foundation’s v0.1.1 capabilities.
  • DSPex Foundation (Our Application Layer): This is the focus of our implementation. It will be built using foundation and will add its own dependencies (like Nx, Explorer, etc.) to provide AI-specific functionality.

Component 1: AI Provider Client (DSPEx.Client)

This component requires a robust HTTP client and JSON parser to communicate with external provider APIs. The resilience logic (circuit breaking, rate limiting) will be provided by the foundation hex package.

LibrarySourceRole in DSPex FoundationPlacement
ReqAwesome Elixir (HTTP)The DSPEx.Client.HttpWorker will use Req internally to execute the actual HTTP requests to LM providers. Its middleware and testing capabilities are well-suited for this.DSPex foundation
JasonAwesome Elixir (JSON)Will be used by the HttpWorker for all JSON serialization (request bodies) and deserialization (API responses). It is the de facto standard for high-performance JSON in Elixir.DSPex foundation

Component 2: Prompt Template Engine (DSPEx.PromptTemplate)

This component is a core, custom-built part of the DSPex value proposition. It does not require external libraries for its templating logic.

  • This will be a net-new, custom module within the DSPex foundation. It will handle the parsing of template strings into an AST and the logic for rendering and composition. Its only dependencies will be on core Elixir/OTP.

Component 3: Semantic & Multi-Tier Cache (DSPEx.Cache)

This component requires a flexible caching framework, a high-performance in-memory store, and the core building blocks for machine learning to enable semantic search.

LibrarySourceRole in DSPex FoundationPlacement
NebulexAwesome Elixir (Caching)Selected as the primary framework for managing the multi-tier caching architecture (L1, L2, L3). Its pluggable adapter system is ideal for this structure.DSPex foundation
CachexAwesome Elixir (Caching)Will be used as the high-performance implementation for the L1 (in-memory, local) cache tier, configured as a Nebulex adapter.DSPex foundation
NxAwesome ML & GenAI (Core)The foundational library for numerical computing. It will be used by DSPEx.Cache to handle the vector embeddings required for semantic similarity calculations.DSPex foundation
AxonAwesome ML & GenAI (Deep Learning)Used to define and run the model that generates embeddings from prompt text. This model will be called by the caching layer before a semantic search.DSPex foundation
BumblebeeAwesome ML & GenAI (Deep Learning)Used to easily load a pre-trained sentence-transformer model from the Hugging Face Hub. This significantly accelerates the development of the semantic embedding generation for the cache.DSPex foundation
RagAwesome ML & GenAI (LLM Tools)The DSPEx.Cache’s L3 (semantic) tier will use a vector database. The Rag library’s client implementations for pgvector or Chroma will be used to interact with the chosen vector store.DSPex foundation

Component 4: Cost & Performance Analytics (DSPEx.Analytics)

This component consumes telemetry data and provides structured analysis. It needs tools for data aggregation and potentially data frame manipulation for user-facing reports.

LibrarySourceRole in DSPex FoundationPlacement
ExplorerAwesome ML & GenAI (Core)The DSPEx.Analytics service’s public API (e.g., get_cost_analysis/2) will return its results as an Explorer.DataFrame. This provides users a powerful and familiar data structure for further analysis.DSPex foundation
StatisticsAwesome Elixir (Statistics)The internal GenServer for DSPEx.Analytics will use this library to calculate statistical aggregates (p95, standard deviation, etc.) from the stream of performance metrics it receives.DSPex foundation

Component 5: Declarative Workflow Engine (DSPEx.Workflow)

This component is a high-level orchestration pattern. It is self-contained and primarily relies on the core capabilities of the foundation library.

  • This will be a net-new, custom module within the DSPex foundation. It is an implementation of the “Chain of Responsibility” pattern and will depend heavily on Foundation.ErrorContext and Foundation.Telemetry to provide automatic tracing and observability for multi-step AI programs. No new external dependencies are required.

Summary of Final Specification

The DSPex Foundation will be a powerful, AI-centric library built directly on top of the generic foundation package. The selected libraries above provide a clear, robust, and modern path to implementing its core components.

  • DSPEx.Client will be built with Req and Jason.
  • DSPEx.PromptTemplate will be custom-built.
  • DSPEx.Cache will be a sophisticated module composed of Nebulex, Cachex, Nx, Axon, Bumblebee, and a Rag vector store client.
  • DSPEx.Analytics will use Explorer and Statistics to provide rich, structured reports.
  • DSPEx.Workflow will be custom-built using foundation’s observability tools.

This strategic selection avoids reinventing the wheel while ensuring that DSPEx leverages the best of the modern Elixir ecosystem for AI and data processing.