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.36.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

indexify_langchain-0.0.36-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file indexify_langchain-0.0.36.tar.gz.

File metadata

  • Download URL: indexify_langchain-0.0.36.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for indexify_langchain-0.0.36.tar.gz
Algorithm Hash digest
SHA256 815d15126698adaed0b873747d4b6352e214b28779d10ee1769e646c24e59ff4
MD5 4f29ad91680fe497597ffa3a08812c35
BLAKE2b-256 e6b9192ffba58136642b23045ba9eddb6bab796f89e01c6e897953ae3fc6322a

See more details on using hashes here.

File details

Details for the file indexify_langchain-0.0.36-py3-none-any.whl.

File metadata

File hashes

Hashes for indexify_langchain-0.0.36-py3-none-any.whl
Algorithm Hash digest
SHA256 73db1c43d5699e4a5a87c3315babfc6fa29a5cf42736a89918f4757c19958587
MD5 ea142e520b2089affcb075bae031fd77
BLAKE2b-256 e4c11e4fdc1089adf2c72f8bb7c573e4006db0ba245cc9b8fb15bb311da23c78

See more details on using hashes here.

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