LangChain streamlines these stages (in figure above) by providing pre-built components and tools for integration, memory management, and deployment, allowing developers to focus on application logic rather than underlying complexities.
Integration of Langchain with LanceDB enables applications to retrieve the most relevant data by comparing query vectors against stored vectors, facilitating effective information retrieval. It results in better and context aware replies and actions by the LLMs.
Quick Start
You can load your document data using langchain’s loaders, for this example we are usingTextLoader and OpenAIEmbeddings as the embedding model.
Documentation
In the above exampleLanceDB vector store class object is created using from_documents() method which is a classmethod and returns the initialized class object.
You can also use LanceDB.from_texts(texts: List[str],embedding: Embeddings) class method.
The exhaustive list of parameters for LanceDB vector store are :
Methods
add_texts()
This method turn texts into embedding and add it to the database.
It returns list of ids of the added texts.
create_index()
This method creates a scalar(for non-vector cols) or a vector index on a table.
For index creation make sure your table has enough data in it. An ANN index is usually not needed for datasets ~100K vectors. For large-scale (>1M) or higher dimension vectors, it is beneficial to create an ANN index.
similarity_search()
This method performs similarity search based on text query.
Return documents most similar to the query without relevance scores.
similarity_search_by_vector()
The method returns documents that are most similar to the specified embedding (query) vector.
It does not provide relevance scores.
similarity_search_with_score()
Returns documents most similar to the query string along with their relevance scores.
It gets called by base class’s
similarity_search_with_relevance_scores which selects relevance score based on our _select_relevance_score_fn.
similarity_search_by_vector_with_relevance_scores()
Similarity search using query vector.
The method returns documents most similar to the specified embedding (query) vector, along with their relevance scores.
max_marginal_relevance_search()
This method returns docs selected using the maximal marginal relevance(MMR). Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
Similarly,
max_marginal_relevance_search_by_vector() function returns docs most similar to the embedding passed to the function using MMR. instead of a string query you need to pass the embedding to be searched for.
add_images()
This method adds images by automatically creating their embeddings and adds them to the vectorstore.
It returns list of IDs of the added images.