Logo IconGuided Mind
v2.4Sign In
Python SDK

Framework Integrations

Use GuidedMind as a retrieval backend inside LangChain, LlamaIndex, and other AI frameworks.

GuidedMind integrates naturally with the most popular Python AI frameworks. Because the SDK follows standard retriever interfaces, you can slot it into existing pipelines with minimal boilerplate.

LangChain

Wrap the Client in a BaseRetriever subclass to use GuidedMind as a drop-in retriever in any LangChain chain.

from langchain_core.retrievers import BaseRetriever
from langchain_core.documents import Document
from langchain_core.callbacks import CallbackManagerForRetrieverRun
from guidedmind import Client, SearchMethod
 
class GuidedMindRetriever(BaseRetriever):
    client: Client
    limit: int = 5
    threshold: float = 0.70
    search_method: SearchMethod = SearchMethod.HYBRID
 
    def _get_relevant_documents(
        self,
        query: str,
        *,
        run_manager: CallbackManagerForRetrieverRun,
    ) -> list[Document]:
        response = self.client.search(
            query=query,
            limit=self.limit,
            threshold=self.threshold,
            search_method=self.search_method,
        )
        return [
            Document(
                page_content=r.content,
                metadata=r.metadata or {},
            )
            for r in response.results
        ]

Usage in a RAG Chain

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough
from guidedmind import Client
 
retriever = GuidedMindRetriever(client=Client(), limit=5)
 
prompt = ChatPromptTemplate.from_template(
    "Answer the question using only the context below.\n\n"
    "Context: {context}\n\nQuestion: {question}"
)
 
chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | ChatOpenAI(model="gpt-4o")
    | StrOutputParser()
)
 
answer = chain.invoke("What is our return policy for enterprise customers?")
print(answer)

LlamaIndex

Use GuidedMindRetriever as a custom retriever in any LlamaIndex query engine.

from llama_index.core.retrievers import BaseRetriever
from llama_index.core.schema import NodeWithScore, TextNode, QueryBundle
from guidedmind import Client
 
class GuidedMindRetriever(BaseRetriever):
    def __init__(self, client: Client, top_k: int = 5):
        self._client = client
        self._top_k = top_k
        super().__init__()
 
    def _retrieve(self, query_bundle: QueryBundle) -> list[NodeWithScore]:
        response = self._client.search(
            query=query_bundle.query_str,
            limit=self._top_k,
        )
        return [
            NodeWithScore(
                node=TextNode(text=r.content, metadata=r.metadata or {}),
                score=r.score,
            )
            for r in response.results
        ]

Usage in a Query Engine

from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.llms.openai import OpenAI
from guidedmind import Client
 
retriever = GuidedMindRetriever(client=Client(), top_k=5)
 
query_engine = RetrieverQueryEngine.from_args(
    retriever=retriever,
    llm=OpenAI(model="gpt-4o"),
)
 
response = query_engine.query("How do I configure the pipeline?")
print(response)

Haystack

from haystack import component, Document
from guidedmind import Client
 
@component
class GuidedMindDocumentRetriever:
    def __init__(self, client: Client, top_k: int = 5):
        self.client = client
        self.top_k = top_k
 
    @component.output_types(documents=list[Document])
    def run(self, query: str):
        response = self.client.search(query=query, limit=self.top_k)
        docs = [Document(content=r.content) for r in response.results]
        return {"documents": docs}

All three integrations above work with the async client too — just swap the sync retriever methods for their async equivalents and use await.