Skip to content

Retrieval Documentation

Functions

create_retrieval_tool(vectorstore)

Creates a LangChain retrieval tool to query account details.

Parameters:

Name Type Description Default
vectorstore

The vectorstore object.

required

Returns:

Name Type Description
Tool Tool

Configured LangChain Tool instance for document retrieval.

Example
tool = create_retrieval_tool(my_vectorstore)
response = tool.run("Invoice for FedEx shipments")
print(response)

is_substring_of_any(doc, seen_texts)

Check if the content of a document is a substring of any text in the provided set.

Parameters:

Name Type Description Default
doc Document

The document to be checked.

required
seen_texts set

Set of previously observed document texts.

required

Returns:

Name Type Description
bool bool

True if doc.page_content is a substring of any text in seen_texts, False otherwise.

Example
doc = Document(page_content="Hello world!")
seen_texts = {"Hello", "Hello world! This is an example."}
result = is_substring_of_any(doc, seen_texts)
print(result)  # Output: True

retrieve_accounts(vectorstore, query, retrieved_examples=5)

Retrieves formatted account details from the vectorstore based on query relevance.

Parameters:

Name Type Description Default
vectorstore

Vectorstore object for semantic retrieval.

required
query str

The query string.

required
retrieved_examples int

Number of documents to retrieve. Default is 5.

5

Returns:

Name Type Description
str str

Formatted text containing retrieved document details.

Example
output = retrieve_accounts(vectorstore, "invoice from FedEx")
print(output)

retrieve_from_pcg(vectorstore, test_query, retrieved_examples=5)

Retrieve unique, relevant documents from a vectorstore based on semantic similarity.

Parameters:

Name Type Description Default
vectorstore

Vectorstore object supporting semantic search.

required
test_query str

The query string used for retrieval.

required
retrieved_examples int

Number of top documents to retrieve. Default is 5.

5

Returns:

Type Description
List[Tuple[Document, float]]

List[Tuple[Document, float]]: A list of tuples with Documents and their similarity scores.

Example
results = retrieve_from_pcg(vectorstore, "invoice number details", 3)
for doc, score in results:
    print(doc.page_content, score)