Build a RAG assistant with LangChain and VectorAmp
Use the VectorAmp LangChain integration when you want LangChain orchestration with VectorAmp handling hosted embeddings, SABLE-backed retrieval, metadata filters, and dataset storage.
What you will build
A small RAG assistant that retrieves context from a VectorAmp dataset and passes the context into a LangChain chain.
Prerequisites
- Python 3.10+.
- A VectorAmp API key.
- A dataset ID with documents already ingested, or documents you will add from Python.
- An LLM integration for generation.
Step 1: Install packages
pip install langchain-vectoramp langchain
If you use OpenAI for the generator:
pip install langchain-openai
Step 2: Configure the vector store
from langchain_vectoramp import VectorAmpVectorStore
store = VectorAmpVectorStore(
api_key="vsk_...", # or set VECTORAMP_API_KEY
dataset_id="ds_123",
)
Step 3: Add documents or use existing ingested content
For small examples, add text directly:
store.add_texts(
[
"VectorAmp uses SABLE for filter-native vector search.",
"Metadata filters are planned before retrieval, not bolted on after.",
],
metadatas=[
{"source": "architecture", "team": "platform"},
{"source": "architecture", "team": "platform"},
],
)
For production, prefer VectorAmp source ingestion for Drive, S3, GCS, web, Jira, Confluence, or file uploads.
Step 4: Retrieve with filters
docs = store.similarity_search(
"How does VectorAmp handle metadata filters?",
k=5,
filter={"team": "platform"},
)
for doc in docs:
print(doc.page_content)
print(doc.metadata)
Step 5: Use the retriever in a chain
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
retriever = store.as_retriever(
search_kwargs={"k": 5, "filter": {"team": "platform"}}
)
prompt = ChatPromptTemplate.from_messages([
("system", "Answer using only the provided context. Cite source metadata when possible."),
("human", "Question: {question}\n\nContext:\n{context}"),
])
llm = ChatOpenAI(model="gpt-4o-mini")
question = "How does VectorAmp handle metadata filters?"
context_docs = retriever.invoke(question)
context = "\n\n".join(doc.page_content for doc in context_docs)
answer = (prompt | llm).invoke({"question": question, "context": context})
print(answer.content)
Production notes
- Keep tenant and role filters on the server side when building user-facing apps.
- Store source IDs, URLs, or document IDs in metadata so answers can link back to original content.
- Use VectorAmp ingestion for large or frequently updated corpora.
- Treat the LLM answer as synthesis; VectorAmp retrieval provides the evidence.
Validation checklist
- Retrieval returns expected documents before adding the LLM.
- Filters exclude documents from other teams or tenants.
- Generated answers include source references.
- Failure modes are clear when no relevant context is found.