Skip to main content

No project description provided

Project description

Indexify Langchain

PyPI version

This package contains our LangChain Retriever component, which leverages LLMs to fetch data with langchain. In order to use this retriever you must have Indexify, to read more about getting started with indexify you can read our getting started documentation.

Requirements

Indexify Retriever RAG Example

Below is an example on how you can use our indexify client and langchain retriever with OpenAI in a basic RAG example.

from indexify_langchain import IndexifyRetriever

# Initialize Indexify client
client = IndexifyClient.create_namespace("test-langchain")
client.add_extraction_policy(
    "tensorlake/minilm-l6",
    "minilml6",
)

# Add Documents
client.add_documents("Lucas is from Atlanta Georgia")

# Initialize retriever
params = {"name": "minilml6.embedding", "top_k": 9}
retriever = IndexifyRetriever(client=client, params=params)

# Setup Chat Prompt Template
from langchain.prompts import ChatPromptTemplate

template = """You are an assistant for question-answering tasks. 
Use the following pieces of retrieved context to answer the question. 
If you don't know the answer, just say that you don't know. 
Use three sentences maximum and keep the answer concise.
Question: {question} 
Context: {context} 
Answer:
"""
prompt = ChatPromptTemplate.from_template(template)

# Ask llm question with retriever context
from langchain_openai import ChatOpenAI
from langchain.schema.runnable import RunnablePassthrough
from langchain.schema.output_parser import StrOutputParser

llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)

rag_chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

# Ask LLM Question
query = "Where is Lucas from?"
print(rag_chain.invoke(query))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

indexify_langchain-0.0.19.tar.gz (2.4 kB view hashes)

Uploaded Source

Built Distribution

indexify_langchain-0.0.19-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page