JSPM

@langchain/core

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1832931
  • Score
    100M100P100Q202432F
  • License MIT

Core LangChain.js abstractions and schemas

Package Exports

  • @langchain/core
  • @langchain/core/agents
  • @langchain/core/caches
  • @langchain/core/callbacks/base
  • @langchain/core/callbacks/dispatch
  • @langchain/core/callbacks/dispatch/web
  • @langchain/core/callbacks/manager
  • @langchain/core/callbacks/promises
  • @langchain/core/chat_history
  • @langchain/core/context
  • @langchain/core/document_loaders/base
  • @langchain/core/document_loaders/langsmith
  • @langchain/core/documents
  • @langchain/core/embeddings
  • @langchain/core/example_selectors
  • @langchain/core/indexing
  • @langchain/core/language_models/base
  • @langchain/core/language_models/chat_models
  • @langchain/core/language_models/llms
  • @langchain/core/load
  • @langchain/core/load/serializable
  • @langchain/core/memory
  • @langchain/core/messages
  • @langchain/core/messages/tool
  • @langchain/core/output_parsers
  • @langchain/core/output_parsers/openai_functions
  • @langchain/core/output_parsers/openai_tools
  • @langchain/core/outputs
  • @langchain/core/package.json
  • @langchain/core/prompt_values
  • @langchain/core/prompts
  • @langchain/core/retrievers
  • @langchain/core/retrievers/document_compressors
  • @langchain/core/runnables
  • @langchain/core/runnables/graph
  • @langchain/core/singletons
  • @langchain/core/stores
  • @langchain/core/structured_query
  • @langchain/core/tools
  • @langchain/core/tracers/base
  • @langchain/core/tracers/console
  • @langchain/core/tracers/log_stream
  • @langchain/core/tracers/run_collector
  • @langchain/core/tracers/tracer_langchain
  • @langchain/core/types/stream
  • @langchain/core/utils/async_caller
  • @langchain/core/utils/chunk_array
  • @langchain/core/utils/env
  • @langchain/core/utils/event_source_parse
  • @langchain/core/utils/function_calling
  • @langchain/core/utils/hash
  • @langchain/core/utils/json_patch
  • @langchain/core/utils/json_schema
  • @langchain/core/utils/math
  • @langchain/core/utils/stream
  • @langchain/core/utils/testing
  • @langchain/core/utils/tiktoken
  • @langchain/core/utils/types
  • @langchain/core/vectorstores

Readme

🦜🍎️ @langchain/core

npm License: MIT Twitter

@langchain/core contains the core abstractions and schemas of LangChain.js, including base classes for language models, chat models, vectorstores, retrievers, and runnables.

💾 Quick Install

pnpm install @langchain/core

🤔 What is this?

@langchain/core contains the base abstractions that power the rest of the LangChain ecosystem. These abstractions are designed to be as modular and simple as possible. Examples of these abstractions include those for language models, document loaders, embedding models, vectorstores, retrievers, and more. The benefit of having these abstractions is that any provider can implement the required interface and then easily be used in the rest of the LangChain ecosystem.

For example, you can install other provider-specific packages like this:

pnpm install @langchain/openai

And use them as follows:

import { StringOutputParser } from "@langchain/core/output_parsers";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { ChatOpenAI } from "@langchain/openai";

const prompt = ChatPromptTemplate.fromTemplate(
  `Answer the following question to the best of your ability:\n{question}`
);

const model = new ChatOpenAI({
  model: "gpt-4o-mini",
  temperature: 0.8,
});

const outputParser = new StringOutputParser();

const chain = prompt.pipe(model).pipe(outputParser);

const stream = await chain.stream({
  question: "Why is the sky blue?",
});

for await (const chunk of stream) {
  console.log(chunk);
}

/*
The
 sky
 appears
 blue
 because
 of
 a
 phenomenon
 known
 as
 Ray
leigh
 scattering
*/

Note that for compatibility, all used LangChain packages (including the base LangChain package, which itself depends on core!) must share the same version of @langchain/core. This means that you may need to install/resolve a specific version of @langchain/core that matches the dependencies of your used packages.

📦 Creating your own package

Other LangChain packages should add this package as a dependency and extend the classes within. For an example, see the @langchain/anthropic in this repo.

Because all used packages must share the same version of core, packages should never directly depend on @langchain/core. Instead they should have core as a peer dependency and a dev dependency. We suggest using a tilde dependency to allow for different (backwards-compatible) patch versions:

{
  "name": "@langchain/anthropic",
  "version": "0.0.3",
  "description": "Anthropic integrations for LangChain.js",
  "type": "module",
  "author": "LangChain",
  "license": "MIT",
  "dependencies": {
    "@anthropic-ai/sdk": "^0.10.0"
  },
  "peerDependencies": {
    "@langchain/core": "~0.3.0"
  },
  "devDependencies": {
    "@langchain/core": "~0.3.0"
  }
}

We suggest making all packages cross-compatible with ESM and CJS using a build step like the one in @langchain/anthropic, then running pnpm build before running npm publish.

💁 Contributing

Because @langchain/core is a low-level package whose abstractions will change infrequently, most contributions should be made in the higher-level LangChain package.

Bugfixes or suggestions should be made using the same guidelines as the main package. See here for detailed information.

Please report any security issues or concerns following our security guidelines.