Skip to content

Conversation

@eLysgaard
Copy link
Collaborator

This PR introduces @databricks/langchain-ts, a TypeScript package that integrates Databricks Model Serving with the LangChain JS SDK. This is the TypeScript equivalent of the existing Python databricks-langchain integration.

Features

  • ChatDatabricks - Core chat model implementation extending LangChain's BaseChatModel
  • Streaming - Full SSE streaming support via _streamResponseChunks()
  • Tool/Function Calling - bindTools() with support for OpenAI format tools, LangChain StructuredTools, and plain object definitions
  • Unified Authentication - Uses @databricks/sdk-experimental for auth (PAT, OAuth M2M, Azure CLI/MSI, GCP credentials)
  • Dual Module Format - ESM + CommonJS builds for broad compatibility

Usage

  import { ChatDatabricks } from "@databricks/langchain-ts";

  const model = new ChatDatabricks({
    endpoint: "databricks-meta-llama-3-3-70b-instruct",
  });

  // Basic invocation
  const response = await model.invoke("Hello!");

  // Streaming
  for await (const chunk of await model.stream("Tell me a story")) {
    process.stdout.write(chunk.content);
  }

  // Tool calling
  const modelWithTools = model.bindTools([...]);

  Package Structure

  integrations/langchain-js/
  ├── src/
     ├── index.ts              # Main exports
     ├── chat_models.ts        # ChatDatabricks implementation
     ├── types.ts              # OpenAI-compatible types
     ├── utils/
        ├── http.ts           # HTTP client with SSE streaming
        ├── messages.ts       # Message conversion utilities
        └── tools.ts          # Tool conversion utilities
     └── tests/
         ├── chat_models.test.ts      # Unit tests
         └── chat_models.int.test.ts  # Integration tests
  ├── examples/
     └── basic.ts              # Usage example
  ├── package.json
  └── README.md

Dependencies

Package Purpose
@langchain/core (peer) Base classes, message types
@databricks/sdk-experimental Authentication
zod Schema validation
zod-to-json-schema Tool schema conversion

Test Plan

  • Unit tests pass (npm test) - 16 tests covering message/tool conversion
  • TypeScript type checking passes (npm run typecheck)
  • ESLint passes (npm run lint)
  • Build produces ESM + CJS outputs (npm run build)
  • Example runs successfully against Databricks workspace (npm run example)
  • Integration tests against live endpoint (npm run test:integration)

Future Work (not in this PR)

  • DatabricksEmbeddings - Embeddings API support
  • DatabricksVectorSearch - Vector search integration
  • withStructuredOutput() - JSON mode / JSON schema support
  • Responses API support for agent endpoints

@eLysgaard eLysgaard self-assigned this Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant