Integrations API
The Integrations API provides details on how to integrate the Tatry Python SDK with other frameworks and libraries.
LangChain
The Tatry Python SDK includes components that work out-of-the-box with LangChain to enhance retrieval capabilities.
TatryRetrieverLangchain
The TatryRetrieverLangchain class allows you to use Tatry as a retriever in your LangChain applications.
from content_retriever.integrations.langchain import TatryRetrieverLangchain
from langchain.chains import RetrievalQA
from langchain.chat_models import ChatOpenAI
# Initialize LLM
llm = ChatOpenAI(temperature=0)
# Initialize Tatry retriever
retriever = TatryRetrieverLangchain(api_key="your-api-key")
# Create a simple QA chain
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=retriever,
chain_type="stuff" # Simple document concatenation
)
# Use the chain
response = qa_chain.run("What are the key features of quantum computing?")
print(response)Initialization
TatryRetrieverLangchain(api_key: str, base_url: Optional[str] = None, top_k: int = 5)api_key(str): Your Tatry API key.base_url(Optional[str]): The base URL for the Tatry API. Defaults to the production API.top_k(int): The number of documents to retrieve. Defaults to 5.
Usage
The TatryRetrieverLangchain class implements the BaseRetriever interface from LangChain, so it can be used in any LangChain component that expects a retriever.
documents = retriever.get_relevant_documents(query="What are quantum computers?")query(str): The search query.
Returns:
- A list of
Documentobjects from LangChain.
LlamaIndex
The Tatry Python SDK can be integrated with LlamaIndex to enhance retrieval capabilities in your RAG applications.
TatryRetrieverLlamaIndex
To use Tatry as a retriever in your LlamaIndex applications, you can create a custom Retriever class that uses the Tatry API.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import NodeWithScore
from content_retriever.integrations.tatry import TatryRetriever
class TatryRetrieverLlamaIndex(BaseRetriever):
def __init__(self, api_key: str, top_k: int = 5):
self._tatry_retriever = TatryRetriever(api_key=api_key)
self._top_k = top_k
def _retrieve(self, query: str, **kwargs):
documents = self._tatry_retriever.retrieve(query=query, max_results=self._top_k)
nodes_with_scores = []
for doc in documents:
node = NodeWithScore(node=TextNode(text=doc["content"], extra_info=doc["metadata"]), score=doc["relevance_score"])
nodes_with_scores.append(node)
return nodes_with_scores
# Usage
api_key = "your-api-key"
tatry_retriever = TatryRetrieverLlamaIndex(api_key=api_key, top_k=5)
# Build basic LlamaIndex
index = VectorStoreIndex.from_documents([], service_context=service_context)
query_engine = index.as_query_engine(retriever=tatry_retriever)
response = query_engine.query("What are the key features of quantum computing?")
print(response)Usage
The TatryRetrieverLlamaIndex class implements the BaseRetriever interface from LlamaIndex, so it can be used in any LlamaIndex component that expects a retriever.
from content_retriever.integrations.tatry import TatryRetriever
tatry_retriever = TatryRetriever(api_key="your-api-key")
documents = tatry_retriever.retrieve(query="What are quantum computers?", max_results=5)query(str): The search query.max_results(int): The number of documents to retrieve. Defaults to 5.
Returns:
- A list of
Documentobjects.