Talk to Salesforce Data Using OpenAI, LangChain & ChromaDB
Build a conversational AI that understands your Salesforce CRM data using Retrieval-Augmented Generation (RAG)
01 What is RAG (Retrieval-Augmented Generation)?
Expanded with a short video on how RAG fits into how AI works, current OpenAI model and embedding notes, and LangChain and Chroma version notes for the 2023 code. Originally published December 2023.
What's New in This Update (November 2026)
- Added: a short video that explains RAG as part of how AI works
- Updated: OpenAI model notes (gpt-4 access ended on October 23, 2026) and embedding model details with prices
- Added: a table of import and package differences between the 2023 code and current LangChain
- Updated: Chroma notes limited to what the Chroma docs state
- Updated: Salesforce native RAG notes (Data 360, Agentforce Data Library)
This is blog post 2 in my AI series. In this tutorial, I'll share source code and a video walkthrough for using LangChain with OpenAI embeddings and ChromaDB vector database to create a conversational interface for Salesforce Lead data.
The concept behind this is called RAG - Retrieval-Augmented Generation. Instead of relying solely on the LLM's training data, we provide it with relevant context from our own database, helping the model answer about your specific Salesforce records.
LLMs don't know about your specific customer data. RAG lets you "teach" the AI about your leads, opportunities, and accounts by providing relevant context at query time—without fine-tuning or retraining models.
02 Architecture Overview
The RAG architecture for this demo follows these key steps:
Key Components
| Component | Purpose | Current Note |
|---|---|---|
| LangChain | Orchestration framework for LLM applications | LangChain v1 moved legacy chains to langchain-classic; see section 5 |
| ChromaDB | Open-source vector database | Chroma 1.0.0 rewrote much of Chroma in Rust; Chroma reports 4× faster local writes and queries in its own benchmark |
| OpenAI Embeddings | Convert text to vector representations | text-embedding-3-small or text-embedding-3-large |
| GPT Model | Generate natural language responses | A current model from OpenAI's models page (gpt-4 access ended October 23, 2026) |
03 Implementation Steps
Here's a summary of what the demo code accomplishes:
- Get data from Salesforce - Connect via OAuth and export Lead records to a text file
- Convert to embeddings - Use OpenAI's embedding model to create vector representations and store them in ChromaDB
- Query with context - When a user asks a question, LangChain retrieves relevant chunks from ChromaDB to enrich the prompt
- Generate response - OpenAI's GPT model answers questions using the retrieved context
Sample Code Structure
Original 2023 example, kept as published; see "2023 Code vs Current Libraries" in section 5 for current package and model notes.
# Key imports
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import ConversationalRetrievalChain
from langchain.chat_models import ChatOpenAI
# Create embeddings and store in ChromaDB
embeddings = OpenAIEmbeddings()
vectorstore = Chroma.from_documents(
documents=salesforce_docs,
embedding=embeddings,
persist_directory="./chroma_db"
)
# Create conversational chain
llm = ChatOpenAI(model_name="gpt-4")
qa_chain = ConversationalRetrievalChain.from_llm(
llm=llm,
retriever=vectorstore.as_retriever(),
return_source_documents=True
)
# Query your Salesforce data
response = qa_chain({
"question": "Which leads are from the technology industry?",
"chat_history": []
})
04 Complete Source Code
The full Python implementation is available on GitHub. This includes Salesforce authentication, data extraction, embedding generation, and the conversational interface:
05 Updates & Best Practices
Several things have changed since this article was first published. Each note below was checked against the vendor's documentation on 9 November 2026.
Chroma Updates
- Rust rewrite: Chroma's 1.0.0 announcement says "local Chroma is 4× faster for common write and query workflows, thanks to a new core written in Rust." Chroma's benchmark used a "Dataset of 1M OpenAI 1536 dimensional embeddings. Using default local Chroma settings on a 12 core M2 Macbook." Treat 4× as Chroma's figure for that setup, not a guarantee for your workload. The same page says "No more waiting for the GIL." (Chroma 1.0.0)
- BM25 and SPLADE: Chroma's site lists "Lexical search (BM25, SPLADE)" under sparse vector search, and its changelog (October 2025) says "First class support for BM25 and SPLADE vectors." The Chroma introduction lists "Dense, sparse, and hybrid search." (trychroma.com)
- JavaScript client V3: Chroma's changelog (June 20, 2025): "We just published a rewrite of our JavaScript/TypeScript client focused on decreasing bundle size and improving DX." (JS client V3)
- Regex search: Chroma documents "$regex and $not_regex operators" for pattern matching in document filters.
OpenAI Embedding Models
| Model | Default dimensions | Price per 1M input tokens |
|---|---|---|
| text-embedding-3-large | 3072 (adjustable with the dimensions parameter) | $0.13 |
| text-embedding-3-small | 1536 (adjustable with the dimensions parameter) | $0.02 |
Source: OpenAI embeddings guide and pricing page, read on 9 November 2026.
Salesforce Native RAG (Agentforce)
Salesforce describes RAG in Agentforce as part of how its Atlas Reasoning Engine works. Salesforce Help says that when you add a data library, the platform builds a search index and retriever for you in Data 360 (formerly Data Cloud). See Setting Up Data Libraries. The article says "The data source is indexed on Data Cloud where a search index and retriever are automatically created for you." That feature is the Agentforce Data Library (ADL).
2023 Code vs Current Libraries
The sample code in section 3 and the gist in section 4 are the original 2023 version and are kept unchanged. Differences to expect when you run them today, from the official docs read on 9 November 2026:
| 2023 code | Now | Source |
|---|---|---|
ChatOpenAI(model_name="gpt-4") |
OpenAI's deprecations page lists gpt-4, gpt-4-turbo and gpt-4-1106-preview as shut down on October 23, 2026. Pick a current model from the models page. | OpenAI deprecations |
from langchain.chat_models import ChatOpenAI |
LangChain v1 says to install provider packages directly; its examples import ChatOpenAI from langchain_openai. |
LangChain v1 migration |
from langchain.embeddings.openai import OpenAIEmbeddings |
The RAG tutorial imports OpenAIEmbeddings from langchain_openai. |
LangChain RAG tutorial |
from langchain.vectorstores import Chroma |
The tutorial shows pip install -qU langchain-chroma and from langchain_chroma import Chroma. |
LangChain RAG tutorial |
ConversationalRetrievalChain |
The migration guide says legacy chains moved to langchain-classic. It does not name this class, so check the package. The current tutorial builds an agent instead of a chain. |
LangChain v1 migration |
Production RAG Best Practices
- Agentic RAG: Let an agent decide when to retrieve, as the current LangChain RAG tutorial does
- Hierarchical chunking: Preserve document structure, validate chunk boundaries semantically
- Smart routing: Send simple questions to cheaper models and cache repeated answers
- Observability: Integrate with LangSmith for production monitoring and debugging
06 Frequently Asked Questions
07 Related Reading
Continue your Salesforce and AI learning journey with these related guides:
- Salesforce Security Ultimate Guide - Comprehensive guide to securing your Salesforce org and data
- 7 Ways to Secure Experience Cloud - Best practices for protecting your Salesforce community
- Solution vs Technical Architect - Understanding Salesforce architect roles and career paths
08 Abbreviations & Glossary
Technical Terms
Reference guide for abbreviations and technical terms used in this article.
Hello Sir, I am getting error. can we call on google meet?