Class: LangChat
The main entry point for the LangChat SDK. Wraps LangChatEngine and returns typed ChatResponse objects.
Constructor
*).
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.
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.
ChatResponse
Example:
chat_sync()
Synchronous wrapper around chat(). Blocks until the response is ready.
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).
dict with:
chunks_indexed(int) — chunks addedchunks_skipped(int) — duplicates skippedfiles_processed(int) — files successfully loadederrors(list) — files that failed to load
get_session()
Get or create a UserSession for a user.
load_env() (class method)
Load a .env file into the environment. Call this before creating LangChat.
Properties
LangChatEngine
Access to the underlying
LangChatEngine instance.