Skip to content

Conversation

@amotl
Copy link

@amotl amotl commented Jan 29, 2025

Hi there,

thanks a stack for conceiving Langflow. Hereby, we are adding another vector store adapter for CrateDB, which is effectively the same like the one for PostgreSQL/PGVector, because CrateDB is compatible with PostgreSQL.

With kind regards,
Andreas.

Summary by CodeRabbit

  • New Features

    • Introduced a CrateDB vector store component with search capabilities.
    • Added CrateDB icon support to the interface.
  • Documentation

    • Added a new section detailing the CrateDB vector store component, its inputs, outputs, and usage.
  • Chores

    • Updated dependencies to include support for CrateDB integration.
  • Tests

    • Added integration tests for CrateDB vector store functionality.

@amotl amotl marked this pull request as ready for review January 29, 2025 23:11
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jan 29, 2025
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 5, 2025
@amotl amotl changed the title Add LangChain vector store adapter for CrateDB feat: Add LangChain vector store adapter for CrateDB Feb 5, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 5, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 5, 2025
@ogabrielluiz
Copy link
Contributor

Hey @amotl

I was not able to run Langflow because the icon you provided is not valid. Could you take a look at it, please?

Copy link
Author

@amotl amotl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ogabrielluiz, thanks for your reply. I hope we can resolve the icon/logo issue soon. I've provided a few bits of information below, within a PR discussion thread attached to the cratedb.svg file.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 5, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 5, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 11, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 12, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 12, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 12, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 12, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Feb 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new CrateDB vector store component was added, including backend logic, documentation, integration tests, and frontend icon integration. The backend supports ingesting and searching documents in CrateDB, while the frontend introduces a CrateDB icon. The dependency langchain-cratedb was added to the project requirements.

Changes

Files / File Groups Change Summary
docs/docs/Components/components-vector-stores.md Added documentation section for the new CrateDB Vector Store component, detailing usage, inputs, and outputs.
pyproject.toml Added langchain-cratedb<0.2 to the dependency list.
src/backend/base/langflow/components/vectorstores/init.py Imported and exported CrateDBVectorStoreComponent in the vectorstores package.
src/backend/base/langflow/components/vectorstores/cratedb.py Introduced CrateDBVectorStoreComponent class and helper for document conversion.
src/backend/tests/integration/components/cratedb/test_cratedb_component.py Added integration tests for CrateDB vector store component, including setup, ingestion, and search scenarios.
src/frontend/src/icons/CrateDB/CrateDB.jsx Added new SvgCrateDBIcon React component rendering the CrateDB SVG icon.
src/frontend/src/icons/CrateDB/index.tsx Added CrateDBIcon component with ref forwarding, wrapping the SVG icon.
src/frontend/src/icons/eagerIconImports.ts Imported and mapped CrateDBIcon in the eager icon imports mapping.
src/frontend/src/icons/lazyIconImports.ts Added lazy-loaded import for CrateDBIcon in the lazy icon imports mapping.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CrateDBVectorStoreComponent
    participant CrateDBVectorStore
    participant CrateDB

    User->>CrateDBVectorStoreComponent: Provide configuration (URL, collection, embedding, etc.)
    CrateDBVectorStoreComponent->>CrateDBVectorStore: Build or load vector store
    CrateDBVectorStore->>CrateDB: Connect and initialize collection/table

    User->>CrateDBVectorStoreComponent: Ingest documents
    CrateDBVectorStoreComponent->>CrateDBVectorStore: Add documents
    CrateDBVectorStore->>CrateDB: Store embeddings

    User->>CrateDBVectorStoreComponent: Search query
    CrateDBVectorStoreComponent->>CrateDBVectorStore: Perform similarity/MMR search
    CrateDBVectorStore->>CrateDB: Query embeddings
    CrateDB-->>CrateDBVectorStore: Return search results
    CrateDBVectorStore->>CrateDBVectorStoreComponent: Return results
    CrateDBVectorStoreComponent-->>User: Return search results as Data objects
Loading

Suggested labels

size:M, lgtm, refactor

Suggested reviewers

  • mfortman11
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch cratedb
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 17, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
src/frontend/src/icons/CrateDB/index.tsx (1)

1-9: Refine the props type to avoid using {}.
Biome flags {} as a banned type. Use React.SVGProps<SVGSVGElement> to accurately type SVG props:

-export const CrateDBIcon = forwardRef<
-  SVGSVGElement,
-  React.PropsWithChildren<{}>
->  ((props, ref) => {
+export const CrateDBIcon = forwardRef<
+  SVGSVGElement,
+  React.SVGProps<SVGSVGElement>
+>((props, ref) => {
   return <SvgCrateDBIcon ref={ref} {...props} />;
 });
src/frontend/src/icons/CrateDB/CrateDB.jsx (1)

3-8: Consider making size theme-aware

Hard-coding width="600"/height="600" forces a 600×600 icon unless callers override both props.
Omitting them (or using 1em) lets consumers size the icon with CSS like every other icon in the set.

src/backend/tests/integration/components/cratedb/test_cratedb_component.py (1)

66-69: Dimension initialisation likely too small

_init_models_with_dimensionality(3) configures vectors of length 3, whereas OpenAI embeddings are 1536-D.
Using an arbitrary small value may mask real-world errors. Prefer vector_store._init_models_with_dimensionality(1536) or compute dynamically from the embedding.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b773513 and b483318.

⛔ Files ignored due to path filters (2)
  • src/frontend/src/icons/CrateDB/cratedb.svg is excluded by !**/*.svg
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • docs/docs/Components/components-vector-stores.md (1 hunks)
  • pyproject.toml (1 hunks)
  • src/backend/base/langflow/components/vectorstores/__init__.py (2 hunks)
  • src/backend/base/langflow/components/vectorstores/cratedb.py (1 hunks)
  • src/backend/tests/integration/components/cratedb/test_cratedb_component.py (1 hunks)
  • src/frontend/src/icons/CrateDB/CrateDB.jsx (1 hunks)
  • src/frontend/src/icons/CrateDB/index.tsx (1 hunks)
  • src/frontend/src/icons/eagerIconImports.ts (2 hunks)
  • src/frontend/src/icons/lazyIconImports.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
src/backend/base/langflow/components/vectorstores/__init__.py (1)
src/backend/base/langflow/components/vectorstores/cratedb.py (1)
  • CrateDBVectorStoreComponent (11-70)
src/frontend/src/icons/eagerIconImports.ts (1)
src/frontend/src/icons/CrateDB/index.tsx (1)
  • CrateDBIcon (4-9)
src/frontend/src/icons/CrateDB/index.tsx (1)
src/frontend/src/icons/CrateDB/CrateDB.jsx (1)
  • SvgCrateDBIcon (1-74)
src/backend/base/langflow/components/vectorstores/cratedb.py (3)
src/backend/base/langflow/base/vectorstores/model.py (2)
  • LCVectorStoreComponent (41-193)
  • check_cached_vector_store (17-38)
src/backend/base/langflow/helpers/data.py (1)
  • docs_to_data (14-23)
src/backend/base/langflow/schema/data.py (2)
  • Data (23-275)
  • to_lc_document (139-149)
src/backend/tests/integration/components/cratedb/test_cratedb_component.py (2)
src/backend/base/langflow/components/vectorstores/cratedb.py (4)
  • CrateDBVectorStoreComponent (11-70)
  • cratedb_collection_to_data (73-90)
  • build_vector_store (32-56)
  • search_documents (58-70)
src/backend/base/langflow/schema/data.py (1)
  • Data (23-275)
🪛 Biome (1.9.4)
src/frontend/src/icons/CrateDB/index.tsx

[error] 6-6: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🪛 Pylint (3.3.7)
src/backend/tests/integration/components/cratedb/test_cratedb_component.py

[error] 15-15: No name 'components' in module 'langflow'

(E0611)


[error] 16-16: No name 'schema' in module 'langflow'

(E0611)


[error] 42-42: No name 'components' in module 'langflow'

(E0611)

🔇 Additional comments (8)
pyproject.toml (1)

100-100: Verify the new package dependency constraint.
Ensure that langchain-cratedb<0.2 exists on PyPI and aligns with the compatibility requirements. Consider specifying a minimum tested version (e.g., >=0.1.0,<0.2) to avoid untested or breaking releases.

Run this script to list available versions:

#!/bin/bash
# Verify available versions of langchain-cratedb on PyPI
curl -s https://pypi.org/pypi/langchain-cratedb/json | jq '.releases | keys'
src/frontend/src/icons/eagerIconImports.ts (2)

25-25: Add CrateDBIcon import to eager icon set.
The import path and symbol name are consistent with other icon definitions.


143-143: Register CrateDB in eagerIconsMapping.
Using the key "CrateDB" matches the component name, and its alphabetical placement after Couchbase is correct.

src/backend/base/langflow/components/vectorstores/__init__.py (2)

8-8: Expose CrateDBVectorStoreComponent.
The import from .cratedb aligns with the module structure and mirrors other vector store components.


35-35: Export CrateDBVectorStoreComponent in all.
Including the new component in __all__ makes it publicly accessible via the vectorstores package.

src/frontend/src/icons/lazyIconImports.ts (1)

67-68: Add lazy-loaded CrateDB icon mapping.
The async import path is correct and returns the CrateDBIcon component as default.

docs/docs/Components/components-vector-stores.md (1)

431-438: Document all supported search types & correct defaults

The component accepts "similarity_score_threshold" (see tests) and defaults number_of_results to 4, not 10.

Please update the search_type row and the default column to match the implementation so users don’t configure invalid values.

src/backend/tests/integration/components/cratedb/test_cratedb_component.py (1)

24-30: Skip tests when CrateDB isn’t reachable

The fixture always drops tables; on a machine without a running CrateDB instance this raises a connection error and fails the whole suite.

Recommend:

try:
    engine = sa.create_engine(CRATEDB_SQLALCHEMY_URL)
    with engine.connect() as connection:
        ...
except sa.exc.OperationalError:
    pytest.skip("CrateDB instance not available")

Comment on lines +17 to +29
inputs = [
SecretStrInput(name="server_url", display_name="CrateDB SQLAlchemy URL", required=True),
StrInput(name="collection_name", display_name="Table", required=True),
*LCVectorStoreComponent.inputs,
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"], required=True),
IntInput(
name="number_of_results",
display_name="Number of Results",
info="Number of results to return.",
value=4,
advanced=True,
),
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Missing search_type input

LCVectorStoreComponent’s base helpers expect self.search_type, and tests set it, yet the input isn’t declared here.
Add a StrInput with choices ("Similarity", "MMR", "similarity_score_threshold") to prevent AttributeError at runtime.

🤖 Prompt for AI Agents
In src/backend/base/langflow/components/vectorstores/cratedb.py around lines 17
to 29, the inputs list is missing a declaration for the search_type input, which
is expected by LCVectorStoreComponent and used in tests. Add a StrInput named
"search_type" with display_name "Search Type" and choices set to ["Similarity",
"MMR", "similarity_score_threshold"] to the inputs list to ensure the attribute
exists and prevent runtime AttributeError.

Comment on lines +84 to +89
data_dict = {
"id": doc.id,
"text": doc.document,
}
data_dict.update(doc.cmetadata)
data.append(Data(**data_dict))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Guard against None metadata

doc.cmetadata can be None, causing dict.update(None)TypeError.

-    data_dict.update(doc.cmetadata)
+    if doc.cmetadata:
+        data_dict.update(doc.cmetadata)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
data_dict = {
"id": doc.id,
"text": doc.document,
}
data_dict.update(doc.cmetadata)
data.append(Data(**data_dict))
data_dict = {
"id": doc.id,
"text": doc.document,
}
if doc.cmetadata:
data_dict.update(doc.cmetadata)
data.append(Data(**data_dict))
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/vectorstores/cratedb.py around lines 84
to 89, the code calls dict.update(doc.cmetadata) without checking if
doc.cmetadata is None, which causes a TypeError. Fix this by adding a guard to
ensure doc.cmetadata is not None before calling update, for example by using a
conditional check or defaulting to an empty dictionary when doc.cmetadata is
None.

Comment on lines +5 to +8
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers import docs_to_data
from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect helper import path

docs_to_data lives in langflow.helpers.data, not the package root.

-from langflow.helpers import docs_to_data
+from langflow.helpers.data import docs_to_data

This avoids ImportError in environments where langflow.helpers.__init__ doesn’t re-export the symbol.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers import docs_to_data
from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data
from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/vectorstores/cratedb.py around lines 5
to 8, the import statement for docs_to_data is incorrect as it imports from
langflow.helpers instead of langflow.helpers.data. Update the import path to
import docs_to_data from langflow.helpers.data to prevent ImportError in
environments where langflow.helpers.__init__ does not re-export docs_to_data.

Comment on lines +58 to +70
def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store()

if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
docs = vector_store.similarity_search(
query=self.search_query,
k=self.number_of_results,
)

data = docs_to_data(docs)
self.status = data
return data
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Duplicated search logic bypasses MMR & score-threshold paths

This override always calls similarity_search, ignoring search_type and duplicates logic already present in the base class.
Consider deleting the method entirely and relying on LCVectorStoreComponent.search_documents, or delegate:

-    def search_documents(self) -> list[Data]:
-        vector_store = self.build_vector_store()
-        ...
-            docs = vector_store.similarity_search(
-                query=self.search_query,
-                k=self.number_of_results,
-            )
+    # Remove this override; the base implementation already handles
+    # caching and dispatches to vector_store.search with the chosen
+    # search_type.

This instantly enables MMR and score-threshold searches without extra code.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store()
if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
docs = vector_store.similarity_search(
query=self.search_query,
k=self.number_of_results,
)
data = docs_to_data(docs)
self.status = data
return data
return []
# Remove this override; the base implementation already handles
# caching and dispatches to vector_store.search with the chosen
# search_type.
🤖 Prompt for AI Agents
In src/backend/base/langflow/components/vectorstores/cratedb.py around lines 58
to 70, the search_documents method duplicates logic from the base class and
always calls similarity_search, ignoring search_type and bypassing MMR and
score-threshold functionality. To fix this, remove this method entirely so the
class inherits the base class's search_documents method, which handles all
search types correctly including MMR and score-threshold, thereby avoiding code
duplication and enabling full search functionality without extra code.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 17, 2025
@autofix-ci
Copy link
Contributor

autofix-ci bot commented Jun 17, 2025

Hi! I'm autofix logoautofix.ci, a bot that automatically fixes trivial issues such as code formatting in pull requests.

I would like to apply some automated changes to this pull request, but it looks like I don't have the necessary permissions to do so. To get this pull request into a mergeable state, please do one of the following two things:

  1. Allow edits by maintainers for your pull request, and then re-trigger CI (for example by pushing a new commit).
  2. Manually fix the issues identified for your pull request (see the GitHub Actions output for details on what I would like to change).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants