Home Salesforce About
RAG TUTORIAL • UPDATED NOVEMBER 2026

Talk to Salesforce Data Using OpenAI, LangChain & ChromaDB

Build a conversational AI that understands your Salesforce CRM data using Retrieval-Augmented Generation (RAG)

Concept
RAG
Architecture Pattern
Embeddings
3072
Default Dimensions, text-embedding-3-large
Guide
text-embedding-3
Embedding model family covered in section 5
Guide
Python
Implementation language of the sample code

01 What is RAG (Retrieval-Augmented Generation)?

How AI Works: Tokens, Context, Agents and the Harness, Explained Simply
Updated November 2026

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.

Why RAG for Salesforce?
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:

1. Extract Data
Get Lead records from Salesforce via REST API
>
2. Convert to Text
Format records as text documents
>
3. Create Embeddings
Generate vectors using OpenAI API
>
4. Store in ChromaDB
Persist vectors for fast retrieval
>
5. Query with LangChain
Conversational retrieval chain

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:

  1. Get data from Salesforce - Connect via OAuth and export Lead records to a text file
  2. Convert to embeddings - Use OpenAI's embedding model to create vector representations and store them in ChromaDB
  3. Query with context - When a user asks a question, LangChain retrieves relevant chunks from ChromaDB to enrich the prompt
  4. 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.

Python
# 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": []
})
Cost Optimization: ChromaDB stores embeddings locally (with persist_directory), so you embed your records once instead of on every run. Each question still needs one embedding call for the question itself plus the chat model call.

04 Complete Source Code

Using Langchain, ChromaDB to talk to your Salesforce Data

The full Python implementation is available on GitHub. This includes Salesforce authentication, data extraction, embedding generation, and the conversational interface:

Open the gist on GitHub

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.

Dimension Reduction: OpenAI's guide says these models can shorten embeddings "by passing in the dimensions API parameter." For example, you can ask text-embedding-3-large for 1024 values instead of 3072, which needs less storage. Keep the same dimensions for every record you store in one collection.

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

  1. Agentic RAG: Let an agent decide when to retrieve, as the current LangChain RAG tutorial does
  2. Hierarchical chunking: Preserve document structure, validate chunk boundaries semantically
  3. Smart routing: Send simple questions to cheaper models and cache repeated answers
  4. Observability: Integrate with LangSmith for production monitoring and debugging

06 Frequently Asked Questions

RAG is a technique that combines retrieval-based and generative AI models. It retrieves relevant information from a knowledge base (using vector embeddings) and uses that context to generate more accurate, grounded responses from an LLM. This allows AI to answer questions about your specific data without retraining.
ChromaDB is an open-source vector database that stores embeddings locally or in the cloud. It reduces OpenAI API costs because you embed your records once and store them. It enables fast semantic search over your Salesforce records and supports persistence.
OpenAI's two third-generation embedding models: text-embedding-3-large (3072 dimensions by default, $0.13 per 1M input tokens) and text-embedding-3-small (1536, $0.02). Both accept a dimensions parameter. Start with small and test large on your own questions.
Salesforce Data 360 (formerly Data Cloud) supports native RAG through Agentforce. Salesforce Help says that when you add a data library, the platform builds a search index and retriever for you. This can suit organizations already invested in the Salesforce ecosystem; this tutorial's approach gives you full control instead.
Key strategies include: (1) Store embeddings in ChromaDB so you don't regenerate them, (2) Use the dimensions parameter to shrink vectors, (3) Route simple queries to cheaper models, (4) Use hierarchical chunking so each retrieved chunk is more useful.

07 Related Reading

Continue your Salesforce and AI learning journey with these related guides:

08 Abbreviations & Glossary

Technical Terms

Reference guide for abbreviations and technical terms used in this article.

RAG - Retrieval-Augmented Generation
LLM - Large Language Model
API - Application Programming Interface
GPT - Generative Pre-trained Transformer
CRM - Customer Relationship Management
OAuth - Open Authorization Protocol
ADL - Agentforce Data Library
BM25 - Best Matching 25 (ranking function)
GIL - Global Interpreter Lock (Python)
SPLADE - Sparse lexical retrieval model
Data 360 - Salesforce data platform, formerly Data Cloud
Link copied to clipboard!
@
Previous Post
Converting Salesforce Data into Embeddings with OpenAI and AWS Lambda
Next Post
Talk to any PDF document using AI
Archives by Year
2026 17 2025 16 2024 2 2023 9 2022 8 2021 4 2020 18 2019 16 2018 21 2017 34 2016 44 2015 54 2014 30 2013 31 2012 46 2011 114 2010 162
Search Blog

One response to “Talk to Salesforce Data Using OpenAI, LangChain & ChromaDB | RAG Tutorial 2026”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading