Langchain-RAG
=============
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/pprados/langchain-rag?quickstart=1)
> Note: A [pull-request](https://github.com/langchain-ai/langchain/pull/13910) with this code was proposed to langchain.
When splitting documents for retrieval, there are often conflicting desires:
1. 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.
2. 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
[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pprados/langchain-rag/blob/master/docs/integrations/vectorstores/rag_vectorstore.ipynb)
Or :
- `poetry run python -m ipykernel install --user --name langchain-rag`
- `jupyter lab`
# Tips
`poetry run python -m ipykernel install --user --name langchain-parent`
Raw data
{
"_id": null,
"home_page": "https://www.github.com/pprados/langchain-rag",
"name": "langchain-rag",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Philippe PRADOS",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/cb/f5/5c6e26e4a5ca147b22cf43c14cc877adea0df21afa5c8c3140c274c9f601/langchain_rag-0.3.1.tar.gz",
"platform": null,
"description": "Langchain-RAG\n=============\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/pprados/langchain-rag?quickstart=1)\n\n> Note: A [pull-request](https://github.com/langchain-ai/langchain/pull/13910) with this code was proposed to langchain.\n\nWhen splitting documents for retrieval, there are often conflicting desires:\n\n1. 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.\n2. You also want to maintain documents long enough to retain the context of each chunk.\n\nWhen 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. \n\nThe `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.\n\nThe challenge lies in correctly managing the lifecycle of the three levels of documents:\n- Original documents\n- Chunks extracted from the original documents\n- Transformations of chunks to generate more vectors for improved retrieval\n\nThe `RAGVectorStore`, in combination with other components, is designed to address this challenge.\n\n# Demo\n[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pprados/langchain-rag/blob/master/docs/integrations/vectorstores/rag_vectorstore.ipynb)\n\nOr :\n- `poetry run python -m ipykernel install --user --name langchain-rag`\n- `jupyter lab`\n\n# Tips\n`poetry run python -m ipykernel install --user --name langchain-parent`\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "This is a temporary project while I wait for my langchain [pull-request](https://github.com/langchain-ai/langchain/pull/7278) to be validated.",
"version": "0.3.1",
"project_urls": {
"Homepage": "https://www.github.com/pprados/langchain-rag",
"Repository": "https://www.github.com/pprados/langchain-rag"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6fe1d4dc2b1cd4a6e7ca42d3e6af9137342c6d9f1d0f1d81b7c16ceaff115c31",
"md5": "fc12edb4bb366fadd66b4f3d462b2342",
"sha256": "ae0a129ebb8d85c73319ba96bea08d3c929d503d6f46012d71ed65c00f8b2831"
},
"downloads": -1,
"filename": "langchain_rag-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fc12edb4bb366fadd66b4f3d462b2342",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 24132,
"upload_time": "2024-10-24T08:28:14",
"upload_time_iso_8601": "2024-10-24T08:28:14.872039Z",
"url": "https://files.pythonhosted.org/packages/6f/e1/d4dc2b1cd4a6e7ca42d3e6af9137342c6d9f1d0f1d81b7c16ceaff115c31/langchain_rag-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cbf55c6e26e4a5ca147b22cf43c14cc877adea0df21afa5c8c3140c274c9f601",
"md5": "40b225ac5e6a9cb1c82c5516e4c9e946",
"sha256": "a0ab757bcbd644d662e2d0048cb7bf7d755044da3ea90915fb253749ae3d0937"
},
"downloads": -1,
"filename": "langchain_rag-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "40b225ac5e6a9cb1c82c5516e4c9e946",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 20006,
"upload_time": "2024-10-24T08:28:16",
"upload_time_iso_8601": "2024-10-24T08:28:16.222338Z",
"url": "https://files.pythonhosted.org/packages/cb/f5/5c6e26e4a5ca147b22cf43c14cc877adea0df21afa5c8c3140c274c9f601/langchain_rag-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-24 08:28:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pprados",
"github_project": "langchain-rag",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "langchain-rag"
}