This is a temporary project while I wait for my langchain [pull-request](https://github.com/langchain-ai/langchain/pull/7278) to be validated.
Project description
Langchain-RAG
Note: A pull-request with this code was proposed to langchain.
When splitting documents for retrieval, there are often conflicting desires:
- You may want to keep documents small, ensuring that their embeddings accurately represent their meaning. If they become too long, the embeddings can lose their meaning.
- You also want to maintain documents long enough to retain the context of each chunk.
When you have a lot of documents, and therefore a lot of pieces, it's likely that dozens of pieces have a distance close to the question. Taking only the top 4 is not a good idea. The answer may lie in the 6 or 7 tracks. How can we improve the match between the question and a fragment? By preparing several versions of the fragment, each with an embedding. In this way, one of the versions can be closer to the question than the original fragment. This version is stripped of context. But the context is still needed to answer the question correctly. One strategy consists of breaking down each fragment into different versions, but using the retriever to return to the original fragment.
The RAGVectorStore
strikes a balance by splitting and storing small chunks and different variations of data. During retrieval, it initially retrieves the small chunks but then looks up the parent IDs for those chunks and returns the larger documents.
The challenge lies in correctly managing the lifecycle of the three levels of documents:
- Original documents
- Chunks extracted from the original documents
- Transformations of chunks to generate more vectors for improved retrieval
The RAGVectorStore
, in combination with other components, is designed to address this challenge.
Demo
Or :
poetry run python -m ipykernel install --user --name langchain-rag
jupyter lab
Tips
poetry run python -m ipykernel install --user --name langchain-parent
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain_rag-0.3.1.tar.gz
.
File metadata
- Download URL: langchain_rag-0.3.1.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0ab757bcbd644d662e2d0048cb7bf7d755044da3ea90915fb253749ae3d0937 |
|
MD5 | 40b225ac5e6a9cb1c82c5516e4c9e946 |
|
BLAKE2b-256 | cbf55c6e26e4a5ca147b22cf43c14cc877adea0df21afa5c8c3140c274c9f601 |
File details
Details for the file langchain_rag-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: langchain_rag-0.3.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae0a129ebb8d85c73319ba96bea08d3c929d503d6f46012d71ed65c00f8b2831 |
|
MD5 | fc12edb4bb366fadd66b4f3d462b2342 |
|
BLAKE2b-256 | 6fe1d4dc2b1cd4a6e7ca42d3e6af9137342c6d9f1d0f1d81b7c16ceaff115c31 |