Support LEANN in llamaindex #217#224
Open
AnirbansarkarS wants to merge 1 commit intoyichuan-w:mainfrom
Open
Conversation
feat: Add LEANN vector store integration including implementation, tests, examples, and documentation.
Author
|
@yichuan-w .... enhanced the 217 issue |
Collaborator
|
will look into it, looks fine to me as long as CI is fixed |
Collaborator
|
@AnirbansarkarS bump on this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Walkthrough: LlamaIndex Integration for LEANN
I have successfully implemented a LlamaIndex vector store integration for LEANN. This allows users to use LEANN as a storage-efficient backend for RAG pipelines, achieving up to 97% storage reduction while maintaining compatibility with LlamaIndex features like metadata filtering and hybrid search.
Changes Made
Created a new package structure in packages/llama-index-vector-stores-leann following the standard LlamaIndex integration patterns.
pyproject.toml
: Defines dependencies and package metadata.
base.py
: Core implementation of LeannVectorStore.
README.md
: Documentation on installation and usage.
2. Implementation: LeannVectorStore
The LeannVectorStore class inherits from BasePydanticVectorStore and implements the required methods:
add(): Accumulates nodes and metadata into LeannBuilder.
delete(): Filters out documents and rebuilds the index (as per LEANN's current design).
query(): Executes semantic search via LeannSearcher, including support for metadata filters.
persist(): Finalizes the index build process.
3. Testing and Validation
Created comprehensive unit tests in
test_leann_vector_store.py
.
Verified the integration via runtime import tests and mock setups.
Provided a full usage example in
leann_example.py
.
Verification Results
Import Test
Verified that the package and its dependencies are correctly configured for namespace-compliant imports:
Success core
Success leann
Unit Tests
The unit tests cover:
Basic insertion and retrieval.
Document deletion and index rebuild.
Metadata preservation.
Usage Example
from llama_index.vector_stores.leann import LeannVectorStore
from llama_index.core import VectorStoreIndex, StorageContext
Initialize LEANN
vector_store = LeannVectorStore(
index_path="./my_index_dir",
embedding_model="facebook/contriever"
)
Connect to LlamaIndex
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
Query
query_engine = index.as_query_engine()
response = query_engine.query("What is LEANN?")