Teradata Package for LangChain Function Reference - ask - Teradata® Package for LangChain - Look here for syntax, methods and examples for the functions included in the Teradata langchain-teradata package.
Teradata® Package for LangChain Function Reference
- Deployment
- VantageCloud
- Edition
- Enterprise
- Product
- Teradata® Package for LangChain
- Release Number
- 20.00.00.01
- Published
- December 2025
- ft:locale
- en-US
- ft:lastEdition
- 2025-12-19
- dita:id
- Langchain-Teradata_FxRef_Lake
- Product Category
- Teradata Vantage
- libs.teradata.langchain_teradata.TeradataVectorStore.ask = ask(self, question=None, prompt=None, **kwargs)
- DESCRIPTION:
Performs similarity search in the vector store for
the input question followed by preparing a natural
language response to the user. This method combines
the operation of similarity_search() and prepare_response()
into one call for faster response time.
PARAMETERS:
question:
Optional Argument.
Specifies the question which needs to be answered.
Types: str
question_vector:
Optional Argument.
Specifies the question in vector/embedded form.
Types: str
prompt:
Optional Argument.
Specifies a customized prompt that replaces the internal prompt.
Types: str
data:
Optional Argument.
Specifies table name or corresponding
teradataml DataFrame where the question is stored.
Note: Only one question(row) should be present
in the table.
Types: str or DataFrame
column:
Optional Argument.
Specifies the column name which contains the
question in text format.
Types: str
vector_column:
Optional Argument.
Specifies the column name which contains the
question in embedded format.
Types: str
batch_data:
Required for batch mode.
Specifies the table name or teradataml DataFrame to be indexed for batch mode.
Types: str, teradataml DataFrame
batch_id_column:
Required for batch mode.
Specifies the ID column to be indexed for batch mode.
Types: str
batch_query_column:
Required for batch mode.
Specifies the query column to be indexed for batch mode.
Types: str
batch_vector_column:
Optional Argument.
Specifies the questions in the embedded form.
Types: str
temperature:
Optional Argument.
Specifies the temperature for tuning the chat_completion_model.
Types: float, int
Permitted Values: [0.0, 2.0]
top_k:
Optional Argument.
Specifies the number of similarity matches to be generated.
Default Value: 10
Permitted Values: [1 - 1024]
Types: int
search_threshold:
Optional Argument.
Threshold value to consider matching tables/views while searching.
A higher threshold value limits responses to the top matches only.
Note:
Only applicable when "search_algorithm" is 'VECTOR_DISTANCE' AND 'KMEANS'.
Types: float
search_numcluster:
Optional Argument.
Number of clusters or fraction of train_numcluster to be considered while searching.
Notes:
Applicable when "search_algorithm" is 'KMEANS'.
If you want to pass a fraction of train_numcluster to be used for searching,
the supported range is (0, 1.0].
If you want to pass the exact number of clusters to be used for searching,
the supported range is [1, train_numcluster].
Types: int or float
ef_search:
Optional Argument.
Specify the number of neighbors to consider during search in HNSW graph.
Note:
Applicable when "search_algorithm" is 'HNSW'.
Permitted Values: [1 - 1024]
Types: int
filter:
Optional Argument.
Specifies the filter expression to be used for filtering the results.
Supports logical operators (AND, OR, NOT), comparison operators
(=, !=, <, <=, >, >=), and IN clauses with parentheses grouping.
Notes:
Examples:
* Simple condition: "age > 25"
* Complex condition: "age >= 18 AND status = 'active'"
* IN clause: "category IN ('A', 'B', 'C')"
* Grouped conditions: "(age > 18 AND status = 'active') OR priority = 'high'"
* String matching: "name != 'test' AND description LIKE '%important%'"
Types: str
filter_style:
Optional Argument.
Specifies whether to apply filtering before or after the similarity_search.
Default Value: PRE-FILTERING
Permitted Values: PRE-FILTERING, POST-FILTERING
Types: str
maximal_marginal_relevance:
Optional Argument.
Specifies whether to use Maximal Marginal Relevance (MMR) for retrieving documents.
Types: bool
lambda_multiplier:
Optional Argument.
Lambda multiplier to control the trade-off between relevance and diversity when selecting documents.
Permitted Values: 0.0 to 1.0
Types: float
RETURNS:
str.
RAISES:
TeradataMlException.
EXAMPLES:
# Load necessary imports.
>>> from langchain_teradata import TeradataVectorStore
>>> from teradatagenai import load_data
# Load data into the vector store.
>>> load_data("amazon", "amazon_reviews_25")
# Create an instance of the TeradataVectorStore.
>>> vs = TeradataVectorStore.from_datasets(name="vs",
data="amazon_reviews_25",
data_columns=['rev_text'],
key_columns=['rev_id', 'aid'],
vector_column='VectorIndex',
embedding="amazon.titan-embed-text-v1",
search_algorithm='VECTORDISTANCE',
top_k=10)
>>> custom_prompt = '''List good reviews about the books. Do not assume information.
Only provide information that is present in the data.
Format results like this:
Review ID:
Author ID:
Review:
'''
# Example 1: Perform similarity search in the Vector Store for
# the input question followed by preparing a natural
# language response to the user.
>>> question = 'Are there any reviews saying that the books are inspiring?'
>>> response = vs.ask(question=question, prompt=custom_prompt)
# Example 2: Perform batch similarity search followed by
# prepare response in the Vector Store with temperature of 0.7.
# Creates the TeradataVectorStore instance.
>>> vs = TeradataVectorStore.from_datasets(name="vs",
data = "valid_passages",
data_columns = "passage",
key_columns = "pid",
embedding = "amazon.titan-embed-text-v1",
top_k=10,
search_algorithm="HNSW",
vector_column="VectorIndex")
>>> prompt = "Structure the response briefly in 1-2 lines."
>>> vs.ask(batch_data="home_depot_train",
batch_id_column="product_uid",
batch_query_column="search_term",
prompt=prompt,
temperature=0.7)
# Retrieve the batch ask results.
from teradatagenai import VSApi
>>> ask_results = vs.get_batch_result(api_name=VSApi.Ask)