Hm...let me try again. Just testing in a new
venv
and it works, so maybe I'm just going crazy π
from llama_index.core import SimpleDirectoryReader, StorageContext, Settings, VectorStoreIndex
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.vector_stores.lancedb import LanceDBVectorStore
import lancedb
from llama_index.core.vector_stores import (
MetadataFilter,
MetadataFilters,
FilterOperator,
)
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
documents = SimpleDirectoryReader("./data", filename_as_id=True).load_data()
vector_store = LanceDBVectorStore(uri="./lancedb")
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
)
# print([x.metadata for x in documents])
filters = MetadataFilters(
filters=[
MetadataFilter(key="metadata.file_name", operator=FilterOperator.EQ, value="essay.txt"),
]
)
# LlamaIndex test
retriever = index.as_retriever(filters=filters)
retriever.retrieve("discovered is to talk about space aliens") # This now works!?!