select_examples() — langchain Function Reference
Architecture documentation for the select_examples() function in length_based.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 064f78c2_7411_e02b_7566_cc055cccbf8f["select_examples()"] 0eacfd0f_9944_7bad_618f_81f1c3dafb2a["LengthBasedExampleSelector"] 064f78c2_7411_e02b_7566_cc055cccbf8f -->|defined in| 0eacfd0f_9944_7bad_618f_81f1c3dafb2a becfa088_b785_9211_0e88_b427170ccd8a["aselect_examples()"] becfa088_b785_9211_0e88_b427170ccd8a -->|calls| 064f78c2_7411_e02b_7566_cc055cccbf8f style 064f78c2_7411_e02b_7566_cc055cccbf8f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/example_selectors/length_based.py lines 95–116
def select_examples(self, input_variables: dict[str, str]) -> list[dict]:
"""Select which examples to use based on the input lengths.
Args:
input_variables: A dictionary with keys as input variables
and values as their values.
Returns:
A list of examples to include in the prompt.
"""
inputs = " ".join(input_variables.values())
remaining_length = self.max_length - self.get_text_length(inputs)
i = 0
examples = []
while remaining_length > 0 and i < len(self.examples):
new_length = remaining_length - self.example_text_lengths[i]
if new_length < 0:
break
examples.append(self.examples[i])
remaining_length = new_length
i += 1
return examples
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does select_examples() do?
select_examples() is a function in the langchain codebase, defined in libs/core/langchain_core/example_selectors/length_based.py.
Where is select_examples() defined?
select_examples() is defined in libs/core/langchain_core/example_selectors/length_based.py at line 95.
What calls select_examples()?
select_examples() is called by 1 function(s): aselect_examples.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free