ChatVectorDBChain Class — langchain Architecture
Architecture documentation for the ChatVectorDBChain class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD bc11cd5d_a081_308b_a325_0c46b7e4deb4["ChatVectorDBChain"] be2fab99_c17a_7327_31b8_3526c30ba2b8["BaseConversationalRetrievalChain"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|extends| be2fab99_c17a_7327_31b8_3526c30ba2b8 94993a4e_2523_282e_bb19_84e4ccbd2c96["base.py"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|defined in| 94993a4e_2523_282e_bb19_84e4ccbd2c96 94f644c9_9259_2c31_1318_d68b5ff4c022["_chain_type()"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|method| 94f644c9_9259_2c31_1318_d68b5ff4c022 fa5cb2d6_a8e6_f030_8bc0_d8c64365a74f["_raise_deprecation()"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|method| fa5cb2d6_a8e6_f030_8bc0_d8c64365a74f 91f26d93_49d0_6b76_bf53_e69422a76a37["_get_docs()"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|method| 91f26d93_49d0_6b76_bf53_e69422a76a37 25fe0504_8866_a226_a080_b16cffe920b7["_aget_docs()"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|method| 25fe0504_8866_a226_a080_b16cffe920b7 a0d1fe2a_c733_6034_7b3d_9e4f623f96c1["from_llm()"] bc11cd5d_a081_308b_a325_0c46b7e4deb4 -->|method| a0d1fe2a_c733_6034_7b3d_9e4f623f96c1
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/conversational_retrieval/base.py lines 498–578
class ChatVectorDBChain(BaseConversationalRetrievalChain):
"""Chain for chatting with a vector database."""
vectorstore: VectorStore = Field(alias="vectorstore")
top_k_docs_for_context: int = 4
search_kwargs: dict = Field(default_factory=dict)
@property
def _chain_type(self) -> str:
return "chat-vector-db"
@model_validator(mode="before")
@classmethod
def _raise_deprecation(cls, values: dict) -> Any:
warnings.warn(
"`ChatVectorDBChain` is deprecated - "
"please use `from langchain_classic.chains import "
"ConversationalRetrievalChain`",
stacklevel=4,
)
return values
@override
def _get_docs(
self,
question: str,
inputs: dict[str, Any],
*,
run_manager: CallbackManagerForChainRun,
) -> list[Document]:
"""Get docs."""
vectordbkwargs = inputs.get("vectordbkwargs", {})
full_kwargs = {**self.search_kwargs, **vectordbkwargs}
return self.vectorstore.similarity_search(
question,
k=self.top_k_docs_for_context,
**full_kwargs,
)
async def _aget_docs(
self,
question: str,
inputs: dict[str, Any],
*,
run_manager: AsyncCallbackManagerForChainRun,
) -> list[Document]:
"""Get docs."""
msg = "ChatVectorDBChain does not support async"
raise NotImplementedError(msg)
@classmethod
def from_llm(
cls,
llm: BaseLanguageModel,
vectorstore: VectorStore,
condense_question_prompt: BasePromptTemplate = CONDENSE_QUESTION_PROMPT,
chain_type: str = "stuff",
combine_docs_chain_kwargs: dict | None = None,
callbacks: Callbacks = None,
**kwargs: Any,
) -> BaseConversationalRetrievalChain:
"""Load chain from LLM."""
combine_docs_chain_kwargs = combine_docs_chain_kwargs or {}
doc_chain = load_qa_chain(
llm,
chain_type=chain_type,
callbacks=callbacks,
**combine_docs_chain_kwargs,
)
condense_question_chain = LLMChain(
llm=llm,
prompt=condense_question_prompt,
callbacks=callbacks,
)
return cls(
vectorstore=vectorstore,
combine_docs_chain=doc_chain,
question_generator=condense_question_chain,
callbacks=callbacks,
**kwargs,
)
Extends
Source
Frequently Asked Questions
What is the ChatVectorDBChain class?
ChatVectorDBChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/conversational_retrieval/base.py.
Where is ChatVectorDBChain defined?
ChatVectorDBChain is defined in libs/langchain/langchain_classic/chains/conversational_retrieval/base.py at line 498.
What does ChatVectorDBChain extend?
ChatVectorDBChain extends BaseConversationalRetrievalChain.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free