The index() method
LangChat.index() indexes one file, multiple files, or an entire directory into Pinecone:
Supported file formats
LangChat uses docsuite for file loading, which supports:Chunking
Documents are split into overlapping chunks before indexing. Configure chunk size and overlap:
Overlap ensures sentences aren’t cut off at chunk boundaries. A 200-character overlap on 1000-character chunks means adjacent chunks share roughly their last/first 200 characters.
Duplicate prevention
By default,index() skips chunks it has already indexed. It detects duplicates by hashing each chunk’s content and checking Pinecone metadata:
Namespaces
Use Pinecone namespaces to separate document collections:Full example: build a knowledge base
Return value
index() returns a dict with indexing statistics:
Re-indexing after document updates
When documents change, re-index them withprevent_duplicates=False to replace the old content:
Performance tips
- Index documents once at setup time, not on every server start
- For large document collections (thousands of files), index in batches
- Use smaller
chunk_sizefor large collections to stay within Pinecone’s metadata limits - Monitor
errorsin the return value to catch files that failed to load
