> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LlamaIndex

## Quickstart

LlamaIndex is a well-known framework for building LLM-powered agents over your data with LLMs and workflows.
You can build your LlamaIndex pipeline and persist your metadata and embeddings in LanceDB via the `LanceDBVectorStore` class.

First, install the LlamaIndex-LanceDB integration.

pip install llama-index-vector-stores-LanceDB

Run the below script as an example.

import logging
import sys
import textwrap

import openai

\# Uncomment to see debug logs
\# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
\# logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
from llama\_index.core import (
&#x20;   Document,
&#x20;   SimpleDirectoryReader,
&#x20;   StorageContext,
&#x20;   VectorStoreIndex,
)
from llama\_index.vector\_stores.lancedb import LanceDBVectorStore

openai.api\_key = "sk-..."

documents = SimpleDirectoryReader("./data/your-data-dir/").load\_data()
print("Document ID:", documents\[0].doc\_id, "Document Hash:", documents\[0].hash)

\## For LanceDB Enterprise :
\# vector\_store = LanceDBVectorStore(
\#     uri="db://db\_name", # your remote DB URI
\#     api\_key="sk\_..", # lancedb enterprise api key
\#     region="your-region" # the region you configured
\#     host\_override="https\://your-host.com" # if you have a custom host, otherwise omit this
\# )

vector\_store = LanceDBVectorStore(
&#x20;   uri="./lancedb", mode="overwrite", query\_type="vector"
)
storage\_context = StorageContext.from\_defaults(vector\_store=vector\_store)

index = VectorStoreIndex.from\_documents(documents, storage\_context=storage\_context)
lance\_filter = "metadata.file\_name = 'paul\_graham\_essay.txt' "
retriever = index.as\_retriever(vector\_store\_kwargs=\{"where": lance\_filter})
response = retriever.retrieve("What did the author do growing up?")


The vector store connector will open an existing LanceDB directory or create the directory if it does not exist.

### Filtering

For metadata filtering, you can use a Lance SQL-like string filter as demonstrated in the example above. Additionally, you can also filter using the `MetadataFilters` class from LlamaIndex:

from llama\_index.core.vector\_stores import (
&#x20;   FilterCondition,
&#x20;   FilterOperator,
&#x20;   MetadataFilter,
&#x20;   MetadataFilters,
)

query\_filters = MetadataFilters(
&#x20;   filters=\[
&#x20;       MetadataFilter(
&#x20;           key="creation\_date", operator=FilterOperator.EQ, value="2024-05-23"
&#x20;       ),
&#x20;       MetadataFilter(key="file\_size", value=75040, operator=FilterOperator.GT),
&#x20;   ],
&#x20;   condition=FilterCondition.AND,
)


### Hybrid Search

For complete documentation, refer [here](https://docs.lancedb.com/search/hybrid-search.md). This example uses the `colbert` reranker. Make sure to install necessary dependencies for the reranker you choose.

from lancedb.rerankers import ColbertReranker

reranker = ColbertReranker()
vector\_store.\_add\_reranker(reranker)

query\_engine = index.as\_query\_engine(
&#x20;   filters=query\_filters,
&#x20;   vector\_store\_kwargs=\{
&#x20;       "query\_type": "hybrid",
&#x20;   },
)

response = query\_engine.query("How much did Viaweb charge per month?")


In the snippet above, you can change/specify `query_type` when creating the engine/retriever
to use different search strategies, such as vector search or FTS.

## API reference

> **[LlamaIndex Vector Stores API reference](https://developers.llamaindex.ai/python/framework-api-reference/storage/vector_store/lancedb/)**
>
> See the official LlamaIndex Vector Stores API reference for more details.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.