Back to Langflow

Manage vector data

docs/versioned_docs/version-1.12.0/Develop/knowledge.mdx

1.13.0.dev116.1 KB
Original Source

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import Icon from "@site/src/components/icon"; import PartialGlobalModelProviders from '@site/docs/_partial-global-model-providers.mdx';

Vector data is critical to AI applications. Langflow provides several components to help you store and retrieve vector data in your flows, including embedding models, vector stores, and knowledge bases.

Embedding models

Embedding model components generate text embeddings using a specified Large Language Model (LLM).

There are two common use cases for these components:

  • Store vectors: Generate embeddings for content written to a vector database.
  • Search vectors: Generate an embedding from a query to run a similarity search.

In both cases the embedding model component is attached to a vector store component. For more information, examples, and available options, see Embedding model components.

Alternatively, you can use knowledge bases, which include built-in support for several embedding models.

Vector stores

Vector store components read and write to vector databases. Typically, these components connect to remote databases, but some vector store components support local databases.

As of Langflow 1.12, most vector store bundles, including the Chroma DB component in the visual editor, are not in the default Langflow installation. Knowledge bases still use local Chroma storage in the default installation. You will have to install any additional vector store providers. FOr more information, see Additional bundles.

import PartialVectorRagBlurb from '@site/docs/_partial-vector-rag-blurb.mdx';

<PartialVectorRagBlurb /> <details> <summary>Example: Vector search flow</summary>

import PartialVectorRagFlow from '@site/docs/_partial-vector-rag-flow.mdx';

<PartialVectorRagFlow /> </details>

Knowledge bases

import PartialKbSummary from '@site/docs/_partial-kb-summary.mdx';

<PartialKbSummary />

Create a knowledge base

In this example, you'll create a knowledge base of chunked customer orders. To follow along with this example, download customer-orders.csv to your local machine, or adapt the steps for your own structured data.

  1. On the Projects page page, click <Icon name="Library" aria-hidden="true"/>Knowledge below the list of projects to view and manage your knowledge bases.

  2. To create a new knowledge base, click <Icon name="Plus" aria-hidden="true"/>Add Knowledge.

  3. In the Create Knowledge Base pane, enter a name for your knowledge base, select an embedding model, and select a DB Provider. <PartialGlobalModelProviders /> The DB Provider determines where embeddings are stored. It defaults to the provider configured in Settings → DB Providers. Existing knowledge bases keep their original backend, so changing the global DB Provider only affects new knowledge bases.

    Once you create a knowledge base, you cannot change its embedding model or DB provider. If you need to change either, you must delete and recreate the knowledge base.

  4. Optional: Add Custom Metadata Fields to tag every chunk with additional context. For example, if you're ingesting files from multiple teams, add a field team with a value of support. When the Knowledge Base component searches, you can then filter results to only return chunks where team equals support to keep results scoped to the support team's content.

  5. To configure sources for your knowledge base, click Configure Sources. Optionally, to create an empty knowledge base, click Create.

  6. In the Configure Sources pane, configure the sources for your knowledge base's data, and also how the embedded data will be chunked for vector search retrieval. For this example, click <Icon name="Upload" aria-hidden="true"/>Add Sources, and then select the downloaded customer-orders.csv file from your local machine. The default settings for Chunk Size, Chunk Overlap, and Separator are fine. To continue, click Next Step.

  7. The Review & Build pane allows you to preview your first chunk before you commit to spending tokens to embed all of the data into the knowledge base. A typical chunk size is 512–1000 characters. Smaller chunks support more granular retrieval but they can lose context across chunks. If the chunk isn't what you want to embed, click Back to configure your chunking strategy. To embed this data, click Create.

  8. Your data is embedded as a Knowledge. When it is available to use, the Status changes to Ready.

To use the new knowledge base in a flow, see Use the Knowledge Base component in a flow.

Manage knowledge bases

On the Projects page page, click <Icon name="Library" aria-hidden="true"/>Knowledge below the list of projects to view and manage your knowledge bases.

For each knowledge base, you can see the following information:

  • Name
  • Embedding model
  • Size on disk
  • Number of words, characters, and chunks
  • The average length and size of chunks
  • The knowledge base's status

The icon next to the knowledge base name indicates the source file type:

  • <Icon name="File" aria-hidden="true"/> Red — PDF
  • <Icon name="FileChartColumn" aria-hidden="true"/> Green — CSV
  • <Icon name="FileType" aria-hidden="true"/> Purple — plain text (.txt)
  • <Icon name="FileText" aria-hidden="true"/> Fuchsia — Markdown (.md, .mdx)
  • <Icon name="FileCode" aria-hidden="true"/> Yellow — HTML
  • <Icon name="FileCode" aria-hidden="true"/> Blue — code files (.py, .js, .ts)
  • <Icon name="FileJson" aria-hidden="true"/> Indigo — JSON
  • <Icon name="Layers" aria-hidden="true"/> — multiple source types

Chunking behavior is determined by the embedding model, and the embedding model is set when you create the knowledge base. If you need to change the embedding model, you must delete and recreate the knowledge base.

To update a knowledge base with , click <Icon name="EllipsisVertical" aria-hidden="true"/> More, and then select <Icon name="RefreshCW" aria-hidden="true"/> Update Knowledge Base.

To view a knowledge base's chunks, click <Icon name="EllipsisVertical" aria-hidden="true"/> More, and then select <Icon name="Layers" aria-hidden="true"/> View Chunks.

To delete a knowledge base, click <Icon name="EllipsisVertical" aria-hidden="true"/> More, and then click <Icon name="Trash2" aria-hidden="true"/> Delete. If any flows use the deleted knowledge base, you must update them to use a different knowledge base.

For more information on using knowledge bases in a flow, see the Knowledge Base component documentation.

Configure vector database providers

DB Providers are the vector databases where your knowledge bases and memory bases store and search embeddings. To configure these providers, go to Settings → DB Providers. The selected provider applies to all new knowledge bases and memory bases you create. Existing knowledge bases and memory bases continue to use the provider that was active when they were created.

Chroma (default)

By default, knowledge bases use ChromaDB as a local vector store, with no additional setup required. Knowledge bases are stored local to your Langflow instance. The default storage location depends on your operating system and installation method:

  • Langflow Desktop:
    • macOS: /Users/<username>/.langflow/knowledge_bases
    • Windows: C:\Users\<name>\AppData\Roaming\com.LangflowDesktop\knowledge_bases
  • Langflow OSS:
    • macOS/Windows/Linux/WSL with uv pip install: <path_to_venv>/lib/python3.12/site-packages/langflow/knowledge_bases (Python version can vary. Knowledge bases aren't shared between virtual environments.)
    • macOS/Windows/Linux/WSL with git clone: <path_to_clone>/src/backend/base/langflow/knowledge_bases

If you set the LANGFLOW_CONFIG_DIR environment variable, the knowledge_bases subdirectory is created relative to that path.

To change the default knowledge_bases directory path, set the LANGFLOW_KNOWLEDGE_BASES_DIR environment variable:

bash
export LANGFLOW_KNOWLEDGE_BASES_DIR="/path/to/parent/directory"

Chroma Cloud

To use Chroma Cloud as a database provider, you need a Chroma Cloud account and an API key from Chroma Cloud.

  1. From your Chroma Cloud dashboard, copy your API Key, Tenant, and Database names.

  2. To connect Chroma Cloud to Langflow, click Settings, and then click DB Providers.

  3. Select Chroma Cloud.

  4. Enter the following values:

    • API Key: Enter your Chroma Cloud API key.
    • Tenant: Optionally, enter your tenant name. If blank, defaults to the tenant associated with your API key.
    • Database: Optionally, enter your database name. If blank, defaults to default_database.
    • Region: Optionally, enter your cloud region.
  5. Click Save and Use Chroma Cloud.

    Optionally, click Test Connection to verify that Langflow can reach your Chroma Cloud instance before saving.

    The Chroma Cloud database is now connected to Langflow as a knowledge base provider. To create a knowledge base using this provider, see Create a knowledge base.

OpenSearch

To use OpenSearch as a database provider, you need a running OpenSearch cluster that is accessible to your Langflow instance. This example uses an OpenSearch container running locally, but you can also use a remote OpenSearch instance.

  1. For this example, start a local OpenSearch container with security disabled. This allows you to connect without a username, password, or TLS. This configuration is for example purposes only; it isn't recommended in production environments.

    bash
    podman run -d \
      --name opensearch \
      -p 9200:9200 \
      -p 9600:9600 \
      -e "discovery.type=single-node" \
      -e "plugins.security.disabled=true" \
      -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=YOUR_OPENSEARCH_PASSWORD" \
      opensearchproject/opensearch:latest
    

    :::note OpenSearch 3.x requires OPENSEARCH_INITIAL_ADMIN_PASSWORD to be set even when security is disabled.

    If the password fails validation, container startup exits immediately with Password failed validation.

    The password must adhere to the https://docs.opensearch.org/latest/security/configuration/demo-configuration/#setting-up-a-custom-admin-password[OpenSearch password complexity requirements]. :::

  2. Verify the cluster is reachable:

    bash
    curl -s http://localhost:9200
    

    A successful response indicates that the container has started and can receive requests:

    json
    {
      "name" : "your-node-name",
      "cluster_name" : "docker-cluster",
      "version" : {
        "distribution" : "opensearch",
        "number" : "3.6.0"
      },
      "tagline" : "The OpenSearch Project: https://opensearch.org/"
    }
    

    If you get no response or a connection error, the container might still be starting. Wait a few seconds and try again.

  3. To connect the OpenSearch database to Langflow as a knowledge base, click Settings, and then click DB Providers.

  4. Select OpenSearch.

  5. Enter the following values for the local OpenSearch container:

    • Cluster URL: Enter http://localhost:9200.
    • Username: Leave blank if security is disabled. Otherwise, enter your basic auth username.
    • Password: Leave blank if security is disabled. Otherwise, enter your basic auth password.
    • Default Index name: Enter langflow_knowledge. The OpenSearch index to write and read from. This index is created in the later ingestion step, so it isn't immediately available.
    • Vector field: Enter vector_field. The document field for storing the embedding vector.
    • Text field: Enter text. The document field for storing the chunk text.
    • Use TLS (HTTPS): Turn off. Enable if your cluster uses HTTPS.
    • Verify TLS certificate: Turn off. Enable if your cluster uses CA-signed certificates.

    :::tip The knowledge base name doesn't need to match the OpenSearch index name — it is the internal label used to scope searches within the shared OpenSearch index. :::

  6. Click Save and Use OpenSearch.

    Optionally, click Test Connection to verify that Langflow can reach your OpenSearch cluster before saving.

    The OpenSearch database is now connected to Langflow as a knowledge base provider.

To create a knowledge base using this provider, see Create a knowledge base.

Postgres pgvector

To use Postgres with pgvector as a database provider, you need a PostgreSQL database with the vector extension enabled, a connection role that has CREATE on the target schema, and the Langflow pgvector optional dependency installed. This example uses a Postgres container running locally, but you can also use a remote PostgreSQL instance that has pgvector installed.

:::tip PGVECTOR_CONNECTION_STRING configures the vector store for knowledge bases and memory bases. It is separate from LANGFLOW_DATABASE_URL, which configures Langflow's application database for flows, users, and messages. You can point both at the same PostgreSQL server, or use different databases. :::

  1. Install the pgvector optional dependency in your Langflow environment:

    bash
    uv pip install "langflow[pgvector]"
    

    For more information, see Install custom dependencies.

  2. For this example, start a local Postgres container with pgvector:

    bash
    podman run -d \
      --name pgvector \
      -p 5432:5432 \
      -e POSTGRES_USER=pgvector \
      -e POSTGRES_PASSWORD=pgvector \
      -e POSTGRES_DB=langflow_vectors \
      pgvector/pgvector:pg16
    
  3. Enable the vector extension, and grant Langflow's connection role CREATE on the target schema.

    Langflow does not create the vector extension. If the extension is absent, knowledge-base and memory-base operations fail.

    To create the vector extension, connect to your Langflow server as a superuser and run:

    sql
    CREATE EXTENSION vector;
    

    For the local container in this example:

    bash
    podman exec -it pgvector psql -U pgvector -d langflow_vectors -c "CREATE EXTENSION vector;"
    

    Langflow creates one table per knowledge base on first ingest, so the role in PGVECTOR_CONNECTION_STRING needs CREATE on the target schema. For example:

    sql
    GRANT CREATE ON SCHEMA public TO <role>;
    
  4. Set the PGVECTOR_CONNECTION_STRING environment variable to your Postgres connection string, and then start or restart Langflow:

    bash
    export PGVECTOR_CONNECTION_STRING="postgresql+psycopg://pgvector:pgvector@localhost:5432/langflow_vectors"
    

    You can also use a postgresql:// URL. Langflow normalizes it to the psycopg driver at runtime.

    When PGVECTOR_CONNECTION_STRING is set, new knowledge bases and memory bases default to Postgres pgvector unless you select a different provider.

  5. To connect Postgres pgvector to Langflow, click Settings, and then click DB Providers.

  6. Select Postgres pgvector.

    There are no credentials to enter in the UI. Postgres pgvector is configured from your server environment.

  7. Click Use Postgres pgVector.

    Optionally, click Test Connection to verify that Langflow can reach your Postgres instance before selecting it.

    The Postgres pgvector database is now connected to Langflow as a knowledge base and memory base provider. To create a knowledge base using this provider, see Create a knowledge base. To create a memory base using this provider, see Create a memory base.

See also