7.1

Embeddings, splitters, vector stores, and retrievers

The retrieval interfaces live in langchain-core, the splitters in langchain-text-splitters, and each store in a partner package, and an agent reaches a retriever through a tool.

You copy a retrieval example from 2024. It imports RetrievalQA from langchain.chains and a vector store from langchain_community.vectorstores. The first import fails at the pin, and the second one comes from a package that is sunset.

When you finish this section, you can say which package holds each piece of a retrieval pipeline at the pin. You can also build the pipeline offline, and give it to an agent as a tool.

Where each piece lives

Retriever: an object with invoke(query) that returns a list of Document objects. Its base class is BaseRetriever in langchain-core.

The 0.x namespace held loaders, splitters, stores, and chains in one package. At the pin they are spread over five places:

PiecePackage at the pinWhat is there
Embeddings, VectorStore, BaseRetriever, Documentlangchain-core 1.8.0the base classes, InMemoryVectorStore, DeterministicFakeEmbedding, create_retriever_tool, and the indexing API
init_embeddingslangchain 1.5.0a model string such as openai:text-embedding-3-small to an embeddings object
text splitterslangchain-text-splitters 1.1.3RecursiveCharacterTextSplitter, CharacterTextSplitter, and splitters for Markdown, HTML, code, and JSON
a real store or embedding modela partner packagesuch as langchain-chroma, langchain-qdrant, langchain-openai, and langchain-ollama
MultiQueryRetriever, RetrievalQA, CacheBackedEmbeddingslangchain-classic 1.0.8the old chains and retrievers, kept for migration

The base classes are in core. InMemoryVectorStore keeps vectors in a dict and scores them with cosine similarity in NumPy. langchain.embeddings exports only Embeddings and init_embeddings, and its docstring says that the other embeddings modules moved to langchain-classic. The v1 release notes list the old retrievers among the moves.

PyPI lists langchain-community 0.4.2 as its last release, and its repository is archived. Most loaders and stores of the 0.x years came from there. The Chroma and Qdrant packages live in the main repository, under libs/partners, and each has its own version. For any other store, look for a partner package before you install the community one.

The documentation has no retrieval page in the LangChain tab. The Retrieval entry of the navigation opens a Deep Agents page. That page names two styles: a fixed retrieve-then-answer step, and an agent that decides when to search. The semantic search tutorial builds the pipeline of this section step by step.

The pipeline in the capture kit

Figure 7.1 shows the pipeline of the kit. It runs at index time once, and the agent uses it at query time on each tool call.

Fig. 7.1index time and query time of the retrieval captureflow
Index time and query time of the retrieval capture Two rows. At index time, three Markdown files go to RecursiveCharacterTextSplitter from langchain-text-splitters, which makes 7 chunks of at most 80 characters. OllamaEmbeddings from langchain-ollama, with the model nomic-embed-text, turns each chunk into 768 numbers, and InMemoryVectorStore from langchain-core keeps them as doc-0 to doc-6. At query time, create_agent asks the model, the model calls the tool search_docs, the tool calls a retriever from as_retriever with k equal to 1, the retriever searches the store, and the ToolMessage carries chunk doc-0 back to the model, which starts with "[checkpoints.md] A checkpointer saves graph state after each step." INDEX TIME: ONCE 3 files checkpoints.md and two more TextSplitter Recursive, size 80 7 chunks embedding nomic-embed-text 768 numbers each vector store InMemory doc-0 to doc-6 langchain-text-splitters langchain-ollama langchain-core QUERY TIME: EACH TOOL CALL create_agent model node tools node search_docs @tool, one argument: query retriever as_retriever k=1 search The start of the ToolMessage back to the model: [checkpoints.md] A checkpointer saves graph state after each step. nomic-embed-text on Ollama picked chunk 0 of 7 for the question of the model.
Three files become seven chunks and seven vectors once, then each search_docs call asks a retriever that searches the same in-memory store. Read the top row from left to right for index time, then the bottom row for one tool call. The package of each piece is under its box.

The splitter

Text splitter: an object that cuts a document into chunks of at most chunk_size characters, with chunk_overlap characters repeated between two chunks.

RecursiveCharacterTextSplitter tries to cut at paragraph breaks first, then at line breaks, then at spaces. The kit cuts three short files with a size of 80 and an overlap of 20:

jsonthe first two chunks of checkpoints.mdFull log
  {
    "source": "checkpoints.md",
    "chars": 77,
    "text": "A checkpointer saves graph state after each step. InMemorySaver keeps it in a"
  },
  {
    "source": "checkpoints.md",
    "chars": 75,
    "text": "keeps it in a dict. SqliteSaver writes it to a file, so a thread survives a"
  },
Two of the seven chunks. The overlap is the words keeps it in a.

The splitter cuts at a space, so a chunk ends in the middle of a sentence. The first chunk stops at in a, and the next chunk repeats those words. Each chunk keeps the source metadata of its file, because the kit passed it to create_documents.

The embedding model

Embedding model: an object with embed_query and embed_documents that turns text into a vector of numbers.

The kit uses OllamaEmbeddings(model="nomic-embed-text") from langchain-ollama, on the Ollama server of the x86 server guest. The embedding model is a real model, so the files that use it are recorded files, with the model on the line under the title.

jsonone vector from nomic-embed-textFull log
{
  "dims": 768,
  "first 4": [
    0.051004,
    -0.024986,
    -0.178736,
    0.040572
  ],
  "repeat equal": true,
  "other text equal": false
}

Each vector has 768 numbers. The same text gave the same vector twice in the run, and another text gave another vector. run.py --check does not compare these numbers, because a model made them. It checks that the file has its model line and the strings that expect.py lists.

The vector store

add_documents with explicit ids stores the seven chunks as doc-0 to doc-6. similarity_search_with_score returns pairs of a document and a score. A query that is the exact text of a chunk scores 1.0:

jsona search with the exact text of the first chunkFull log
query 'A checkpointer saves graph state after each step. InMemorySaver keeps it in a':
[
  {
    "id": "doc-0",
    "source": "checkpoints.md",
    "score": 1.0,
…
The query line, then the first hit. The second hit is cut.

The next hit, doc-2, scored 0.556317. It is the last chunk of the same file. A query with other words, Where does long-term memory live?, returned doc-3, the first chunk of stores.md, with 0.683653, and doc-1 from checkpoints.md with 0.455558. The query What does a checkpointer do? returned doc-0 with 0.68785, and doc-2 with 0.507239.

InMemoryVectorStore takes a Python function as its filter. The kit kept only the chunks of stores.md and got doc-3 and doc-4. A partner store takes its own filter syntax, so a filter does not move from one store to another. delete(["doc-0"]) removed the first chunk, and get_by_ids then returned only doc-1. max_marginal_relevance_search for memory returned doc-3 and doc-2.

A retriever as a tool

Vector store retriever: the retriever that as_retriever() returns. It runs one search on the store with the search_kwargs you gave it.

create_agent has no retrieval parameter. You give the agent a tool, and the tool calls the retriever. The kit wraps the retriever in a plain @tool:

pythonthe retriever and the toolFull log
    retriever = store.as_retriever(search_kwargs={"k": 1})

    @tool
    def search_docs(query: str) -> str:
        """Search the local corpus."""
        return "\n".join(f"[{d.metadata['source']}] {d.page_content}" for d in retriever.invoke(query))

The kit asked Qwen3 4B What does a checkpointer do?. The model called search_docs once with that question, and the tool returned one chunk with its source in brackets:

jsonthe tool call and its resultFull log
    "type": "ToolMessage",
    "content": "[checkpoints.md] A checkpointer saves graph state after each step. InMemorySaver keeps it in a",
    "name": "search_docs",
    "id": "<uuid-3>",
    "tool_call_id": "<uuid-2>",
    "status": "success"
The ToolMessage only. The model call before it and the answer after it are cut.

The retriever returned chunk 0 of 7, the first chunk of checkpoints.md, which answers the question. The model answered from it: A checkpointer saves the graph state after each step. For example, the InMemorySaver keeps the state in memory.. With k=1 the model saw one chunk. The chunk stops at keeps it in a, and the words dict and SqliteSaver are in doc-1, which the model did not get. So the answer is right, and it is only as complete as the one chunk.

Put the source into the text of the result. The model sees only the content of the ToolMessage, so it can cite a file only when the tool writes the name into that text. Core also has create_retriever_tool, which builds the same kind of tool from a retriever, a name, and a description. With response_format="content_and_artifact", it also keeps the documents as the artifact of the message.

Index time and query time do different work. The kit embeds every chunk once, before the agent runs. Each tool call embeds only the query. A store that persists, such as a partner store with a server, keeps the index time work across restarts. InMemoryVectorStore loses it when the process ends.

LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11