langchain.js
    Preparing search index...

    Module @langchain/core - v1.0.0-alpha.6

    🦜🍎️ @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.

    pnpm install @langchain/core
    

    @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.

    @langchain/core is currently on version 0.3.x.

    As @langchain/core contains the base abstractions and runtime for the whole LangChain ecosystem, we will communicate any breaking changes with advance notice and version bumps. The exception for this is anything in @langchain/core/beta. The reason for @langchain/core/beta is that given the rate of change of the field, being able to move quickly is still a priority, and this module is our attempt to do so.

    Minor version increases will occur for:

    • Breaking changes for any public interfaces NOT in @langchain/core/beta

    Patch version increases will occur for:

    • Bug fixes
    • New features
    • Any changes to private interfaces
    • Any changes to @langchain/core/beta

    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"
    }
    }

    This recommendation will change to a caret once a major version (1.x.x) release has occurred.

    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.

    We will be exploring how to make this process easier in the future.

    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.

    Modules

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