VectorDBQA Class — langchain Architecture
Architecture documentation for the VectorDBQA class in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ad09c90b_2890_30a7_1895_8c3576656b96["VectorDBQA"] cf809fc8_9926_bc74_caaa_077dffa64d09["BaseRetrievalQA"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|extends| cf809fc8_9926_bc74_caaa_077dffa64d09 d3aa4510_51a9_c393_bb4a_23fe112c52cd["base.py"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|defined in| d3aa4510_51a9_c393_bb4a_23fe112c52cd ab594ff9_7823_bb7e_3f62_9bd5f568c3a7["validate_search_type()"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|method| ab594ff9_7823_bb7e_3f62_9bd5f568c3a7 55d39624_e191_dafc_2c96_8e7034fcaa32["_get_docs()"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|method| 55d39624_e191_dafc_2c96_8e7034fcaa32 5cda0264_b1c1_3e8e_120d_b7697af0e3df["_aget_docs()"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|method| 5cda0264_b1c1_3e8e_120d_b7697af0e3df 1daea205_6ebc_225b_7865_d9eceb158316["_chain_type()"] ad09c90b_2890_30a7_1895_8c3576656b96 -->|method| 1daea205_6ebc_225b_7865_d9eceb158316
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/retrieval_qa/base.py lines 307–368
class VectorDBQA(BaseRetrievalQA):
"""Chain for question-answering against a vector database."""
vectorstore: VectorStore = Field(exclude=True, alias="vectorstore")
"""Vector Database to connect to."""
k: int = 4
"""Number of documents to query for."""
search_type: str = "similarity"
"""Search type to use over vectorstore. `similarity` or `mmr`."""
search_kwargs: dict[str, Any] = Field(default_factory=dict)
"""Extra search args."""
@model_validator(mode="before")
@classmethod
def validate_search_type(cls, values: dict) -> Any:
"""Validate search type."""
if "search_type" in values:
search_type = values["search_type"]
if search_type not in ("similarity", "mmr"):
msg = f"search_type of {search_type} not allowed."
raise ValueError(msg)
return values
@override
def _get_docs(
self,
question: str,
*,
run_manager: CallbackManagerForChainRun,
) -> list[Document]:
"""Get docs."""
if self.search_type == "similarity":
docs = self.vectorstore.similarity_search(
question,
k=self.k,
**self.search_kwargs,
)
elif self.search_type == "mmr":
docs = self.vectorstore.max_marginal_relevance_search(
question,
k=self.k,
**self.search_kwargs,
)
else:
msg = f"search_type of {self.search_type} not allowed."
raise ValueError(msg)
return docs
async def _aget_docs(
self,
question: str,
*,
run_manager: AsyncCallbackManagerForChainRun,
) -> list[Document]:
"""Get docs."""
msg = "VectorDBQA does not support async"
raise NotImplementedError(msg)
@property
def _chain_type(self) -> str:
"""Return the chain type."""
return "vector_db_qa"
Extends
Source
Frequently Asked Questions
What is the VectorDBQA class?
VectorDBQA is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/retrieval_qa/base.py.
Where is VectorDBQA defined?
VectorDBQA is defined in libs/langchain/langchain_classic/chains/retrieval_qa/base.py at line 307.
What does VectorDBQA extend?
VectorDBQA extends BaseRetrievalQA.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free