Index Single Document
Copy
from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase
# Setup
llm = OpenAI(api_key="sk-...", model="gpt-4o-mini")
vector_db = Pinecone(api_key="...", index_name="...")
db = Supabase(url="https://...", key="...")
ai = LangChat(llm=llm, vector_db=vector_db, db=db)
# Index document
result = ai.load_and_index_documents(
file_path="company-handbook.pdf",
chunk_size=1000,
chunk_overlap=200
)
print(f"✅ Indexed {result['chunks_indexed']} chunks")
Index Multiple Documents
Copy
result = ai.load_and_index_multiple_documents(
file_paths=[
"product-catalog.pdf",
"faq-document.txt",
"pricing-guide.csv"
],
chunk_size=1000,
chunk_overlap=200
)
print(f"✅ Total chunks: {result['total_chunks_indexed']}")
print(f"⏭️ Skipped: {result['total_chunks_skipped']}")
Using Namespaces
Organize documents by topic:Copy
# Education documents
ai.load_and_index_documents(
file_path="universities.pdf",
namespace="education"
)
# Travel documents
ai.load_and_index_documents(
file_path="destinations.pdf",
namespace="travel"
)
Complete Example
Copy
from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase
import os
# Setup
llm = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
vector_db = Pinecone(
api_key=os.getenv("PINECONE_API_KEY"),
index_name=os.getenv("PINECONE_INDEX_NAME")
)
db = Supabase(
url=os.getenv("SUPABASE_URL"),
key=os.getenv("SUPABASE_KEY")
)
ai = LangChat(llm=llm, vector_db=vector_db, db=db)
# Index documents
documents = [
"company-handbook.pdf",
"product-catalog.pdf",
"faq-document.txt"
]
for doc in documents:
if os.path.exists(doc):
result = ai.load_and_index_documents(
file_path=doc,
chunk_size=1000,
chunk_overlap=200
)
print(f"✅ {doc}: {result['chunks_indexed']} chunks")
Your documents are now searchable by your chatbot!
Next Steps
- Document Indexing Guide - Complete guide
- Vector Search - Understand search
- Basic Usage - Test your chatbot
Built with ❤️ by NeuroBrain
