Skip to main content

Class: LangChat

The main entry point for the LangChat SDK. Wraps LangChatEngine and returns typed ChatResponse objects.

Constructor

All parameters are keyword-only (note the *).
Any
required
LLM provider instance. From langchat.providers: OpenAI, Anthropic, Gemini, Mistral, Cohere, Ollama.
Any
required
Vector database provider. From langchat.providers: Pinecone.
Any
required
History database provider. From langchat.providers: Supabase.
Any | None
default:"FlashrankRerankAdapter"
Reranker instance. Defaults to FlashrankRerankAdapter(model_name="ms-marco-MiniLM-L-12-v2", top_n=3).
str | None
default:"None"
Custom system prompt. Must include {context}, {chat_history}, {question}. See Prompts guide.
str | None
default:"None"
Custom standalone question prompt. Must include {chat_history} and {question}.
bool
default:"False"
Enable verbose LangChain logging.
int
default:"20"
Number of recent exchanges to include in each prompt. One exchange = one (user, AI) pair.
Example:

Methods

chat()

Send a message and receive a typed response. Async.
str
required
The user’s message.
str
required
Unique identifier for the user. Scopes conversation history.
str
default:"default"
Namespace for the conversation. Use different values to separate conversations for the same user across multiple apps.
Returns: ChatResponse Example:

chat_sync()

Synchronous wrapper around chat(). Blocks until the response is ready.
Same parameters and return type as chat(). Example:

index()

Index documents into Pinecone. Can accept a file path, a list of paths, or a directory.
str | list[str]
required
Path to a file, a list of file paths, or a directory path.
int
default:"1000"
Maximum characters per chunk.
int
default:"200"
Character overlap between adjacent chunks.
str | None
default:"None"
Pinecone namespace to index into.
bool
default:"True"
Skip chunks that are already in Pinecone (detected by content hash).
Returns: dict with:
  • chunks_indexed (int) — chunks added
  • chunks_skipped (int) — duplicates skipped
  • files_processed (int) — files successfully loaded
  • errors (list) — files that failed to load
Example:

get_session()

Get or create a UserSession for a user.
Example:

load_env() (class method)

Load a .env file into the environment. Call this before creating LangChat.
Example:

Properties

LangChatEngine
Access to the underlying LangChatEngine instance.