Module 3 · Index types

VectorStoreIndex and external stores

5 min read

The VectorStoreIndex is the index you will use most: each node is represented by a vector, and a question is resolved by looking for the vectors closest to its own. By default, LlamaIndex keeps everything in memory — perfect for a prototype, unusable in production. This lesson shows how to plug in a real vector database, here Qdrant, and the architectural choices that follow.

From prototype to production

index = VectorStoreIndex.from_documents(documents)   # all in memory, recomputed at each startup

This shortcut splits, embeds and stores the nodes in an in-memory SimpleVectorStore. It can be saved to disk (index.storage_context.persist()), but it doesn't scale: search scans every vector, and nothing is shared between several servers.

A dedicated vector database brings fast approximate search (HNSW index) over millions of vectors, persistence, server-side metadata filters, hybrid search, replication. LlamaIndex integrates with dozens of databases (Qdrant, pgvector, Weaviate, Pinecone, Milvus, Chroma, Elasticsearch…) via llama-index-vector-stores-* packages, which all expose the same interface.

Plugging in Qdrant

Qdrant runs in two modes, with the same client:

ModeLaunchUse
EmbeddedAsyncQdrantClient(path="storage/qdrant") or location=":memory:"Development, tests, single-machine tool
ServerDocker container or managed service; AsyncQdrantClient(url=...)Production

In Lumen, the vector database is the end point of the pipeline and the starting point of the index:

def vector_store(location: str | None = None) -> BasePydanticVectorStore:
    if config.QDRANT_URL:
        return QdrantVectorStore(config.COLLECTION, client=QdrantClient(url=config.QDRANT_URL),
                                 aclient=AsyncQdrantClient(url=config.QDRANT_URL))
    location = location or str(config.STORAGE_DIR / "qdrant")
    if location == ":memory:":
        client = AsyncQdrantClient(location=":memory:")
    else:
        client = AsyncQdrantClient(path=location)
    return QdrantVectorStore(config.COLLECTION, aclient=client)


def knowledge_index(vector_store) -> VectorStoreIndex:
    return VectorStoreIndex.from_vector_store(vector_store, embed_model=models.embed_model())

from_vector_store recomputes nothing: it creates a "view" index on a database already filled by the pipeline. Startup is instant, and the index always reflects the database's content.

Why everything is asynchronous

A constraint of embedded mode shaped Lumen's architecture: an embedded Qdrant folder accepts only one client at a time. Yet LlamaIndex uses the sync client for classic methods (query, retrieve) and the async client for a… methods (aquery, aretrieve) — those used by workflows and agents. Both can't be opened on the same folder.

Lumen therefore makes a consistent choice: everything is asynchronous — ingestion (arun), queries (aquery), conversation (achat), workflows, agents — with the async client only. In server mode, the limitation disappears and Lumen provides both clients. If you forget the async client, the error is explicit: "Async client is not initialized".

It's also a good choice in itself: a web service that queries a vector database and an LLM spends most of its time waiting for the network, which async handles far better than threads.

A vector database also stores the text

Qdrant stores, with each vector, the node's content and metadata (the payload):

{'source': 'products/desk-2.md', 'collection': 'products', 'sku': 'DESK-2', 'header_path': '/',
 'skus': ['DESK-2'], 'doc_id': 'products/desk-2.md_part_0', '_node_content': '…'}

That's what lets from_vector_store rebuild the nodes without any other storage. Not all stores do: LlamaIndex's SimpleVectorStore only keeps vectors, and the text then lives in a separate docstore — from_vector_store actually refuses to use it ("Cannot initialize from a vector store that does not store text").

Stored metadata is used for server-side filters: Qdrant only compares the vectors of nodes that satisfy the filter. Creating payload indexes on filtered fields (in server mode) significantly speeds up these queries.

Vector search understands meaning, but sometimes misses exact matches: a reference ("CASTER-M"), an error code ("E02"), a proper name. Keyword search (BM25 and its variants) does the opposite. Hybrid search combines both scores.

With Qdrant, LlamaIndex enables it by also computing a sparse vector per node:

QdrantVectorStore(
    config.COLLECTION, aclient=client, enable_hybrid=True, fastembed_sparse_model="Qdrant/bm25"
)
index.as_retriever(vector_store_query_mode="hybrid", similarity_top_k=4, sparse_top_k=10)

For product documentation full of references and codes, hybrid search often improves retrieval. As always, measure it on your questions.

Choosing a vector database

CriterionWhat to look at
OperationsAlready running PostgreSQL? pgvector avoids one more service. Otherwise, a dedicated (Qdrant, Weaviate) or managed (Pinecone…) service
VolumeUp to a few million vectors, almost anything works; beyond, check performance and memory cost
FiltersSupported operators, payload indexes, filters on lists
HybridNative hybrid search or not
DataHosting, region, encryption

One point deserves attention: filter operators vary from one database to another. With Qdrant, the ANY operator isn't supported, but EQ on a list field is true as soon as one element matches — Lumen uses it to filter by product reference. Check your integration's documentation before designing your filters.

Key takeaways

  • The in-memory index is a prototype; production goes through a dedicated vector database, all interchangeable via LlamaIndex.
  • The pipeline writes into the database; VectorStoreIndex.from_vector_store creates the index without recomputing anything.
  • Embedded Qdrant accepts one client per folder: Lumen is fully async; in server mode, provide both clients.
  • The database stores vectors, text and metadata, and filters server-side; operators vary by database.
  • Hybrid search (dense + sparse) helps with references, codes and proper names.

Practice

  1. Run Qdrant in Docker (docker run -p 6333:6333 qdrant/qdrant), set LUMEN_QDRANT_URL=http://localhost:6333 and run the examples: explore the collection in Qdrant's web interface.
  2. Try to create the index with from_vector_store on a SimpleVectorStore: read the error and explain it.
  3. Enable hybrid search and compare results for "code erreur E02" with and without it.

Resources