Migrate Chroma to CustomComponent (#784)
Migrating Chroma to CustomComponent
This commit is contained in:
commit
0168b5a626
8 changed files with 198 additions and 72 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
{
|
{
|
||||||
"name": "Langflow Demo Container",
|
"name": "Langflow Demo Container",
|
||||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
"image": "mcr.microsoft.com/devcontainers/python:3.10",
|
"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bullseye",
|
||||||
"features": {
|
"features": {
|
||||||
"ghcr.io/devcontainers/features/aws-cli:1": {},
|
"ghcr.io/devcontainers/features/aws-cli:1": {},
|
||||||
"ghcr.io/devcontainers/features/docker-in-docker": {},
|
"ghcr.io/devcontainers/features/docker-in-docker": {},
|
||||||
|
|
@ -16,7 +16,8 @@
|
||||||
"GitHub.copilot",
|
"GitHub.copilot",
|
||||||
"ms-python.python",
|
"ms-python.python",
|
||||||
"eamodio.gitlens",
|
"eamodio.gitlens",
|
||||||
"GitHub.vscode-pull-request-github"
|
"GitHub.vscode-pull-request-github",
|
||||||
|
"ms-azuretools.vscode-docker"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,26 +15,26 @@
|
||||||
// "forwardPorts": [],
|
// "forwardPorts": [],
|
||||||
|
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
"postCreateCommand": "make install_frontend && make install_backend",
|
"postCreateCommand": "make setup_devcontainer",
|
||||||
|
|
||||||
"containerEnv": {
|
"containerEnv": {
|
||||||
"POETRY_VIRTUALENVS_IN_PROJECT": "true"
|
"POETRY_VIRTUALENVS_IN_PROJECT": "true"
|
||||||
},
|
},
|
||||||
|
|
||||||
// Configure tool-specific properties.
|
// Configure tool-specific properties.
|
||||||
"customizations": {
|
"customizations": {
|
||||||
"vscode": {
|
"vscode": {
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"actboy168.tasks",
|
"actboy168.tasks",
|
||||||
"GitHub.copilot",
|
"GitHub.copilot",
|
||||||
"ms-python.python",
|
"ms-python.python",
|
||||||
"sourcery.sourcery",
|
"sourcery.sourcery",
|
||||||
"eamodio.gitlens",
|
"eamodio.gitlens",
|
||||||
"ms-vscode.makefile-tools",
|
"ms-vscode.makefile-tools",
|
||||||
"GitHub.vscode-pull-request-github"
|
"GitHub.vscode-pull-request-github",
|
||||||
]
|
"ms-azuretools.vscode-docker"
|
||||||
}
|
]}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
// "remoteUser": "root"
|
// "remoteUser": "root"
|
||||||
|
|
|
||||||
13
.gitattributes
vendored
13
.gitattributes
vendored
|
|
@ -7,14 +7,23 @@
|
||||||
*.h text
|
*.h text
|
||||||
*.py text
|
*.py text
|
||||||
*.js text
|
*.js text
|
||||||
*.ts text
|
|
||||||
*.jsx text
|
*.jsx text
|
||||||
|
*.ts text
|
||||||
|
*.tsx text
|
||||||
*.md text
|
*.md text
|
||||||
*.mdx text
|
*.mdx text
|
||||||
|
*.svg text
|
||||||
|
*.yml text
|
||||||
|
*.yaml text
|
||||||
|
*.Dockerfile text
|
||||||
|
Dockerfile text
|
||||||
|
|
||||||
# Declare files that will always have CRLF line endings on checkout.
|
# Declare files that will always have CRLF line endings on checkout.
|
||||||
*.sln text eol=crlf
|
*.sln text eol=crlf
|
||||||
|
|
||||||
# Denote all files that are truly binary and should not be modified.
|
# Denote all files that are truly binary and should not be modified.
|
||||||
*.png binary
|
*.png binary
|
||||||
*.jpg binary
|
*.jpg binary
|
||||||
|
*.ico binary
|
||||||
|
*.gif binary
|
||||||
|
*.mp4 binary
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -253,3 +253,4 @@ langflow.db
|
||||||
.docusaurus/
|
.docusaurus/
|
||||||
|
|
||||||
/tmp/*
|
/tmp/*
|
||||||
|
src/backend/langflow/frontend/
|
||||||
|
|
|
||||||
6
Makefile
6
Makefile
|
|
@ -40,6 +40,12 @@ install_frontendc:
|
||||||
run_frontend:
|
run_frontend:
|
||||||
cd src/frontend && npm start
|
cd src/frontend && npm start
|
||||||
|
|
||||||
|
run_cli:
|
||||||
|
poetry run langflow --path src/frontend/build
|
||||||
|
|
||||||
|
run_cli_debug:
|
||||||
|
poetry run langflow --path src/frontend/build --log-level debug
|
||||||
|
|
||||||
setup_devcontainer:
|
setup_devcontainer:
|
||||||
make init
|
make init
|
||||||
make build_frontend
|
make build_frontend
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,33 @@
|
||||||
version: "3.4"
|
version: "3.4"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
backend:
|
backend:
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
build:
|
build:
|
||||||
context: ./
|
context: ./
|
||||||
dockerfile: ./dev.Dockerfile
|
dockerfile: ./dev.Dockerfile
|
||||||
command:
|
command:
|
||||||
[
|
[
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
"pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m uvicorn --factory src.backend.langflow.main:create_app --host 0.0.0.0 --port 7860 --reload",
|
"pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 -m uvicorn --factory src.backend.langflow.main:create_app --host 0.0.0.0 --port 7860 --reload",
|
||||||
]
|
]
|
||||||
ports:
|
ports:
|
||||||
- 7860:7860
|
- 7860:7860
|
||||||
- 5678:5678
|
- 5678:5678
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
context: ./src/frontend
|
context: ./src/frontend
|
||||||
dockerfile: ./dev.Dockerfile
|
dockerfile: ./dev.Dockerfile
|
||||||
args:
|
args:
|
||||||
- BACKEND_URL=http://backend:7860
|
- BACKEND_URL=http://backend:7860
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
volumes:
|
volumes:
|
||||||
- ./src/frontend/public:/home/node/app/public
|
- ./src/frontend/public:/home/node/app/public
|
||||||
- ./src/frontend/src:/home/node/app/src
|
- ./src/frontend/src:/home/node/app/src
|
||||||
- ./src/frontend/package.json:/home/node/app/package.json
|
- ./src/frontend/package.json:/home/node/app/package.json
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
|
|
||||||
109
src/backend/langflow/components/vectorstores/Chroma.py
Normal file
109
src/backend/langflow/components/vectorstores/Chroma.py
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
from typing import Optional, Union
|
||||||
|
from langflow import CustomComponent
|
||||||
|
|
||||||
|
from langchain.vectorstores import Chroma
|
||||||
|
from langchain.schema import Document
|
||||||
|
from langchain.vectorstores.base import VectorStore
|
||||||
|
from langchain.schema import BaseRetriever
|
||||||
|
from langchain.embeddings.base import Embeddings
|
||||||
|
import chromadb
|
||||||
|
|
||||||
|
|
||||||
|
class ChromaComponent(CustomComponent):
|
||||||
|
"""
|
||||||
|
A custom component for implementing a Vector Store using Chroma.
|
||||||
|
"""
|
||||||
|
|
||||||
|
display_name: str = "Chroma (Custom Component)"
|
||||||
|
description: str = "Implementation of Vector Store using Chroma"
|
||||||
|
documentation = "https://python.langchain.com/docs/integrations/vectorstores/chroma"
|
||||||
|
beta = True
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
"""
|
||||||
|
Builds the configuration for the component.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- dict: A dictionary containing the configuration options for the component.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
"collection_name": {"display_name": "Collection Name", "value": "langflow"},
|
||||||
|
"persist": {"display_name": "Persist"},
|
||||||
|
"persist_directory": {"display_name": "Persist Directory"},
|
||||||
|
"code": {"show": False, "display_name": "Code"},
|
||||||
|
"documents": {"display_name": "Documents", "is_list": True},
|
||||||
|
"embedding": {"display_name": "Embedding"},
|
||||||
|
"chroma_server_cors_allow_origins": {
|
||||||
|
"display_name": "Server CORS Allow Origins",
|
||||||
|
"advanced": True,
|
||||||
|
},
|
||||||
|
"chroma_server_host": {"display_name": "Server Host", "advanced": True},
|
||||||
|
"chroma_server_port": {"display_name": "Server Port", "advanced": True},
|
||||||
|
"chroma_server_grpc_port": {
|
||||||
|
"display_name": "Server gRPC Port",
|
||||||
|
"advanced": True,
|
||||||
|
},
|
||||||
|
"chroma_server_ssl_enabled": {
|
||||||
|
"display_name": "Server SSL Enabled",
|
||||||
|
"advanced": True,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
collection_name: str,
|
||||||
|
persist: bool,
|
||||||
|
chroma_server_ssl_enabled: bool,
|
||||||
|
persist_directory: Optional[str] = None,
|
||||||
|
embedding: Optional[Embeddings] = None,
|
||||||
|
documents: Optional[Document] = None,
|
||||||
|
chroma_server_cors_allow_origins: Optional[str] = None,
|
||||||
|
chroma_server_host: Optional[str] = None,
|
||||||
|
chroma_server_port: Optional[int] = None,
|
||||||
|
chroma_server_grpc_port: Optional[int] = None,
|
||||||
|
) -> Union[VectorStore, BaseRetriever]:
|
||||||
|
"""
|
||||||
|
Builds the Vector Store or BaseRetriever object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- collection_name (str): The name of the collection.
|
||||||
|
- persist_directory (Optional[str]): The directory to persist the Vector Store to.
|
||||||
|
- chroma_server_ssl_enabled (bool): Whether to enable SSL for the Chroma server.
|
||||||
|
- persist (bool): Whether to persist the Vector Store or not.
|
||||||
|
- embedding (Optional[Embeddings]): The embeddings to use for the Vector Store.
|
||||||
|
- documents (Optional[Document]): The documents to use for the Vector Store.
|
||||||
|
- chroma_server_cors_allow_origins (Optional[str]): The CORS allow origins for the Chroma server.
|
||||||
|
- chroma_server_host (Optional[str]): The host for the Chroma server.
|
||||||
|
- chroma_server_port (Optional[int]): The port for the Chroma server.
|
||||||
|
- chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Chroma settings
|
||||||
|
chroma_settings = None
|
||||||
|
|
||||||
|
if chroma_server_host is not None:
|
||||||
|
chroma_settings = chromadb.config.Settings(
|
||||||
|
chroma_server_cors_allow_origins=chroma_server_cors_allow_origins
|
||||||
|
or None,
|
||||||
|
chroma_server_host=chroma_server_host,
|
||||||
|
chroma_server_port=chroma_server_port or None,
|
||||||
|
chroma_server_grpc_port=chroma_server_grpc_port or None,
|
||||||
|
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
# If documents, then we need to create a Chroma instance using .from_documents
|
||||||
|
if documents is not None and embedding is not None:
|
||||||
|
return Chroma.from_documents(
|
||||||
|
documents=documents, # type: ignore
|
||||||
|
persist_directory=persist_directory if persist else None,
|
||||||
|
collection_name=collection_name,
|
||||||
|
embedding=embedding,
|
||||||
|
client_settings=chroma_settings,
|
||||||
|
)
|
||||||
|
|
||||||
|
return Chroma(
|
||||||
|
persist_directory=persist_directory, client_settings=chroma_settings
|
||||||
|
)
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
<svg version="1.0" id="katman_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
<svg version="1.0" id="katman_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
viewBox="0 0 841.89 595.28" style="enable-background:new 0 0 841.89 595.28;" xml:space="preserve">
|
viewBox="0 0 841.89 595.28" style="enable-background:new 0 0 841.89 595.28;" xml:space="preserve">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#505AA5;}
|
.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#505AA5;}
|
||||||
</style>
|
</style>
|
||||||
<path class="st0" d="M349.6,124.45c48.94-54.99,129.98-71.12,196.61-39.38c88.52,42.17,120.82,149.6,72.62,232.48L510.41,503.76
|
<path class="st0" d="M349.6,124.45c48.94-54.99,129.98-71.12,196.61-39.38c88.52,42.17,120.82,149.6,72.62,232.48L510.41,503.76
|
||||||
c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l131.26-225.49c34.97-60.15,11.58-138.11-52.6-168.8
|
c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l131.26-225.49c34.97-60.15,11.58-138.11-52.6-168.8
|
||||||
c-48.16-23.03-107.02-11.53-142.6,28.08c-19.62,21.74-30.64,49.82-31.01,79.01c-0.37,29.2,9.94,57.53,29.01,79.76
|
c-48.16-23.03-107.02-11.53-142.6,28.08c-19.62,21.74-30.64,49.82-31.01,79.01c-0.37,29.2,9.94,57.53,29.01,79.76
|
||||||
c3.43,3.99,7.12,7.75,11.04,11.25l-76.63,131.88c-3,5.16-6.99,9.67-11.74,13.3c-4.76,3.62-10.18,6.28-15.97,7.82
|
c3.43,3.99,7.12,7.75,11.04,11.25l-76.63,131.88c-3,5.16-6.99,9.67-11.74,13.3c-4.76,3.62-10.18,6.28-15.97,7.82
|
||||||
c-5.79,1.54-11.83,1.93-17.77,1.16c-5.94-0.78-11.67-2.71-16.87-5.68l83.19-143.17c-11.95-17.11-20.53-36.31-25.29-56.58
|
c-5.79,1.54-11.83,1.93-17.77,1.16c-5.94-0.78-11.67-2.71-16.87-5.68l83.19-143.17c-11.95-17.11-20.53-36.31-25.29-56.58
|
||||||
L261.1,360.8c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l131.83-226.76
|
L261.1,360.8c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l131.83-226.76
|
||||||
C336.06,141.32,342.43,132.55,349.6,124.45z M501.76,196.63c31.75,18.21,42.71,58.7,24.34,90.22L399.69,503.74
|
C336.06,141.32,342.43,132.55,349.6,124.45z M501.76,196.63c31.75,18.21,42.71,58.7,24.34,90.22L399.69,503.74
|
||||||
c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l117.38-201.93c-9.42-1.97-18.29-5.94-26.01-11.65
|
c-6.06,10.41-16.03,18-27.72,21.11c-11.69,3.11-24.15,1.49-34.64-4.51l117.38-201.93c-9.42-1.97-18.29-5.94-26.01-11.65
|
||||||
c-7.72-5.71-14.1-13.01-18.7-21.4c-4.6-8.4-7.31-17.68-7.95-27.22c-0.64-9.54,0.82-19.1,4.27-28.02c3.45-8.92,8.8-17,15.7-23.67
|
c-7.72-5.71-14.1-13.01-18.7-21.4c-4.6-8.4-7.31-17.68-7.95-27.22c-0.64-9.54,0.82-19.1,4.27-28.02c3.45-8.92,8.8-17,15.7-23.67
|
||||||
c6.9-6.67,15.17-11.77,24.24-14.95c9.08-3.18,18.74-4.37,28.32-3.49S493.43,191.83,501.76,196.63z M455.78,237.39
|
c6.9-6.67,15.17-11.77,24.24-14.95c9.08-3.18,18.74-4.37,28.32-3.49S493.43,191.83,501.76,196.63z M455.78,237.39
|
||||||
c-2.17,1.66-4,3.72-5.36,6.08h-0.01c-2.06,3.55-3.02,7.62-2.75,11.71c0.27,4.09,1.76,8,4.27,11.25c2.51,3.25,5.94,5.69,9.84,7
|
c-2.17,1.66-4,3.72-5.36,6.08h-0.01c-2.06,3.55-3.02,7.62-2.75,11.71c0.27,4.09,1.76,8,4.27,11.25c2.51,3.25,5.94,5.69,9.84,7
|
||||||
c3.91,1.32,8.12,1.45,12.1,0.39c3.99-1.06,7.56-3.27,10.28-6.35c2.72-3.08,4.46-6.89,5-10.95c0.54-4.06-0.15-8.19-1.97-11.87
|
c3.91,1.32,8.12,1.45,12.1,0.39c3.99-1.06,7.56-3.27,10.28-6.35c2.72-3.08,4.46-6.89,5-10.95c0.54-4.06-0.15-8.19-1.97-11.87
|
||||||
c-1.82-3.67-4.71-6.73-8.28-8.78c-2.37-1.36-4.99-2.24-7.71-2.6c-2.72-0.35-5.48-0.18-8.12,0.53
|
c-1.82-3.67-4.71-6.73-8.28-8.78c-2.37-1.36-4.99-2.24-7.71-2.6c-2.72-0.35-5.48-0.18-8.12,0.53
|
||||||
C460.43,234.52,457.95,235.73,455.78,237.39z"/>
|
C460.43,234.52,457.95,235.73,455.78,237.39z"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 1.9 KiB |
Loading…
Add table
Add a link
Reference in a new issue