Introducing Genkit for Go: Build scalable AI-powered apps in Go

JUL 17, 2024
Chris Gill Product Manager
Cameron Balahan Group Product Manager

Following the launch of Firebase Genkit for Node.js at Google I/O, the Firebase and Go teams collaborated to bring Genkit to the Go community. We’re excited to announce Genkit for Go, an open source framework for building AI-powered applications and cloud services natively in Go, leveraging the language's renowned simplicity, scalability, and security.

By combining Go's performance and concurrency advantages with Genkit's libraries and tools, developers can create generative AI applications that leverage the full potential of both technologies. Some potential use cases include:

  • Intelligent assistants that understand complex requests and autonomously execute tasks like booking travel or creating itineraries, all tailored to your user’s preferences.

  • Customer support agents that use retrieval-augmented generation (RAG) to provide fast, accurate, personalized responses grounded in your company’s knowledge base and policies.

  • Powerful data transformation tools that convert unstructured data like natural language into structured formats (SQL queries, tables) for deeper analysis and insights.

Genkit for Go is currently in alpha, making it ideal for experimentation and exploration. We encourage you to prototype your AI-powered projects and share your feedback with us. Your input will directly shape the roadmap of Genkit for Go, helping us empower Go developers to build the next generation of production-ready, scalable AI applications.


Intuitive libraries for AI generation, retrieval, and workflows

Genkit is a developer-first framework for building AI-powered applications. Our Go libraries, written in pure Go, embrace the language's idioms and conventions, making them instantly familiar and productive for Go developers. Genkit provides lightweight, composable abstractions that simplify the development of sophisticated AI workflows without sacrificing customizability and control.

Here are a few ways Genkit boosts your productivity when building generative AI applications:

  • Unified generation API: Generate content from various models (Gemini, Gemma, or third-party) using a single, consistent interface. Easily configure models and leverage powerful features like function calling and structured output.

  • Native vector database support: Make your AI models context-aware by integrating retrieval augmented generation (RAG) into your applications with simple indexing and retrieval APIs that work across vector database providers.

  • “Flows” for AI workflows: Organize multi-step AI workflows with Genkit "flows." Flows are functions that offer built-in observability for debugging and monitoring, integration with Genkit tooling, plus easy deployment as HTTP endpoints with minimal boilerplate.
func main() {
    ctx := context.Background()

    // Initialize the Google AI plugin.
    if err := googleai.Init(ctx, nil); err != nil {
        log.Fatal(err)
    }

    // Define a simple flow that prompts an LLM to generate menu suggestions.
    // Flows are functions that integrate with Genkit tooling and provide
    // observability over multi-step workflows.
    genkit.DefineFlow("menuSuggestionFlow", func(ctx context.Context, input string) (string, error) {

        // Initialize gemini-1.5-flash model from Google AI.
        m := googleai.Model("gemini-1.5-flash")
        if m == nil {
            return "", errors.New("menuSuggestionFlow: failed to find model")
        }

        // Construct a request and send it to the model API (Google AI).
        resp, err := m.Generate(ctx,
            ai.NewGenerateRequest(
                &ai.GenerationCommonConfig{Temperature: 1},
                ai.NewUserTextMessage(fmt.Sprintf(`Suggest an item for the menu of a %s themed restaurant`, input))),
            nil)
        if err != nil {
            return "", err
        }

        // Handle the response from the model API.
        text, err := resp.Text()
        if err != nil {
            return "", fmt.Errorf("menuSuggestionFlow: %v", err)
        }
        return text, nil
    })

    // Initialize Genkit flows server.
    if err := genkit.Init(ctx, nil); err != nil {
        log.Fatal(err)
    }
}

Enhanced prompt engineering and management

Achieving the best AI generation outcomes involves careful consideration of your model, configuration, prompt, and output shape. Genkit provides Dotprompt, a simple file format that streamlines your prompt engineering process.

With Dotprompt, you can define rich prompt templates, input and output schemas, model selection, and model configuration options all within a single .prompt file. This keeps everything organized, making it effortless to test, version, and deploy your prompts alongside your Go code.

---
model: vertexai/gemini-1.5-pro
config:
  temperature: 0.9
input:
  schema:
    location: string
    style?: string
    name?: string
  default:
    location: a restaurant
---

You are the world's most welcoming AI assistant and are currently working at {{location}}.

Greet a guest{{#if name}} named {{name}}{{/if}}{{#if style}} in the style of {{style}}{{/if}}.

Integrate Google and third-party AI services

At its core, Genkit for Go is a lightweight, provider-agnostic framework. We offer a growing collection of plugins to seamlessly integrate with specific models, vector databases, and cloud services from Google and third-party providers.

In this release, Genkit for Go provides the following plugins:

  • Google Cloud Vertex AI plugin: Access Gemini and embeddings models from Vertex AI, Google Cloud’s production-ready AI platform. Support for Google’s image generation models, evaluators, third-party models from Model Garden are coming soon.

  • Ollama plugin: Access and run open source models like Gemma, Llama, and Mistral locally through Ollama.

  • Pinecone plugin: Integrate with Pinecone's vector database for efficient indexing and retrieval operations.

  • Google Cloud telemetry plugin: Export logs, metrics, and traces from your AI-powered apps to Cloud Logging, Cloud Tracing, and Firestore for comprehensive monitoring.

Genkit's plugin system is designed to be open and extensible to any and all models, vector databases, evaluators, tools, and more. We actively encourage the community to contribute to Genkit’s ecosystem by publishing their own plugins.

Stay tuned for the Genkit for Go plugin development guide, coming soon to our documentation!


Integrated developer tooling

Building AI-powered apps comes with unique challenges such as crafting effective prompts, debugging unpredictable output, optimizing retrieval processes, and more. We believe these complexities benefit from dedicated tooling that goes beyond typical IDE utilities.

Genkit's CLI and intuitive browser-based developer UI provide a powerful toolkit to streamline your generative AI development.

With these tools you can:

  • Quickly initialize a new Genkit project or integrate Genkit into an existing project.

  • Interactively run and iterate on your AI workflows, prompts, retrieval queries, and more in dedicated playgrounds for Genkit components.

  • View detailed traces and metadata for the workflows and components you run, providing full observability and efficient debugging.

  • Evaluate your AI workflows against test sets and view scored metrics and links to relevant traces.

If you like working within VS Code or Project IDX, you can open the Genkit developer UI in the IDE’s integrated browser and use it side-by-side with your code.


Production observability

When you’re ready to deploy, Genkit helps you monitor your AI-powered application in production to make sure it’s serving your users as expected. Genkit’s Google Cloud telemetry plugin helps you easily export logs, metrics, and traces from your AI-powered app to Google Cloud’s operations suite.

image1

While we provide Google Cloud integration out-of-the-box, we implemented Genkit’s instrumentation through the widely used OpenTelemetry standard, which can be integrated with many popular observability platforms.


Get started

Now that Genkit for Go is available in alpha, you can start using it to integrate AI workflows into your applications, and join the growing community of Go AI Developers.

To get started, check out the Get Started with Genkit for Go guide.

You can also open the Genkit template in IDX’s pre-configured workspace.

We're eager to collaborate with you!

  • Connect with us on the Genkit Discord server to get direct access to the Genkit team, see announcements, ask questions, and discuss your experience.

  • Share what you built with Genkit on the Show and Tell section of the discussion forums.

Together, let's build a thriving ecosystem for AI development in Go. We can’t wait to see what you build with Genkit!