Skip to main content

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:
Choosing chunk size: 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:
To force re-indexing (e.g., after updating documents):

Namespaces

Use Pinecone namespaces to separate document collections:
Namespaces allow a single Pinecone index to serve multiple use cases.

Full example: build a knowledge base

Run it once to build the index, then run your chatbot normally.

Return value

index() returns a dict with indexing statistics:

Re-indexing after document updates

When documents change, re-index them with prevent_duplicates=False to replace the old content:
Or delete the old vectors from Pinecone and re-index from scratch via the Pinecone dashboard.

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_size for large collections to stay within Pinecone’s metadata limits
  • Monitor errors in the return value to catch files that failed to load