mirror of
https://github.com/lancedb/lancedb.git
synced 2026-10-14 15:52:26 +00:00
Move the public website pages into `docs/web` beside the SDK, with
shared navigation and executable example sources in `docs/web-tests`.
The combined website is assembled by
[lancedb/docs#355](https://github.com/lancedb/docs/pull/355), with six
Enterprise replacements from
[lancedb/sophon#7681](https://github.com/lancedb/sophon/pull/7681).
This includes Function guidance, runnable Quickstarts, regenerated
snippets, production contact/demo fixes, the legacy SQL route, and the
LeRobot redirect. LeRobot remains attributed to Geneva; all 34 Geneva
pages remain in the docs repository until Function officially launches.
Materialized-view guidance follows the full rebuild refresh introduced
by #4373: local refresh writes the complete result, has no `full`
argument, supports `source_version`, and no longer requires stable row
IDs. Deployment SQL refresh options and stable-ID setup are qualified by
version/configuration. Function input guidance distinguishes ordinary
stored columns from computed inputs supported by newer deployments.
**Validation:** independently accepted local checks include 95 Python
tests (real Enterprise excluded), eight TypeScript tests, Rust
Quickstart, snippet parity, typos, deterministic assembly, Mint
validation and links/anchors/redirects. The combined baseline retains
all 181 production routes and 17 legacy redirects. Examples ran locally
against source-built Python SDK 0.40.0b13; existing GitHub workflows do
not run `docs/web-tests`. New main at `069b2f7d` is 0.41.0b0 and adds
computed Function inputs; that SDK was not exercised by the accepted
tests. Latest prose corrections receive focused site validation.
**Merge/rollout:** merge this and #7681 before #355's combined CI, which
reads producer `main`. This is migration infrastructure: section
overlays, source-owned skills and automatic versioned paired releases
remain follow-ups. The current manual publisher is transitional. Hosted
validation, a supported SDK/Enterprise release pair and a real
Enterprise walkthrough remain pending.
Production Mintlify watches `lancedb/docs:deploy-freeze`, directory
`docs`; preserve that source through review. The separate SDK GitHub
Pages reference workflow rebuilds on main merges.
**Updated-head CI (9a50f8db):**
[Typos](https://github.com/lancedb/lancedb/actions/runs/37654185443/job/112904990558),
[PR
title](https://github.com/lancedb/lancedb/actions/runs/37654179507/job/112904974595)
and
[Aikido](https://app.aikido.dev/featurebranch/scan/215386145?groupId=74229)
pass. Critical findings in the example lockfiles were patched: all Sharp
copies use 0.35.5, protobufjs 7.6.6, tar 7.5.22, quinn-proto 0.11.19,
zerovec 0.11.8 and zerovec-derive 0.11.6. The SDK's product dependencies
are unchanged. The revised lockfiles pass eight TypeScript examples,
HuggingFace decode/resize/crop/rescale/normalize plus AVIF roundtrip,
and Rust Quickstart. Aikido passing does not mean every advisory is
cleared; npm still reports 29 high and five moderate advisories in the
example dependency graph. No scanner bypass or suppression was added.
The Function prose correction passes combined/standalone Mint,
deterministic assembly, routes and assets. The revised 325-file site
checksum is
`175bec06864abb400dd292e667ba93448c0479b8359fd7bf6146afabf9040647`. This
PR remains open for independent review; further merges are on hold.
---------
Co-authored-by: Brendan Clement <brendan.clement@lancedb.com>
227 lines
12 KiB
Plaintext
227 lines
12 KiB
Plaintext
---
|
|
title: "LangChain"
|
|
sidebarTitle: "LangChain"
|
|
|
|
---
|
|
|
|
import {
|
|
PyFrameworksLangchainAddImages,
|
|
PyFrameworksLangchainAddTexts,
|
|
PyFrameworksLangchainCreateIndex,
|
|
PyFrameworksLangchainMaxMarginalRelevance,
|
|
PyFrameworksLangchainQuickStart,
|
|
PyFrameworksLangchainSimilaritySearch,
|
|
PyFrameworksLangchainSimilaritySearchByVector,
|
|
PyFrameworksLangchainSimilaritySearchByVectorWithScores,
|
|
PyFrameworksLangchainSimilaritySearchWithScores,
|
|
PyFrameworksLangchainVectorStoreConfig,
|
|
} from '/snippets/integrations.mdx';
|
|
|
|
**LangChain** is a framework designed for building applications with large language models (LLMs) by chaining together various components. It supports a range of functionalities including memory, agents, and chat models, enabling developers to create context-aware applications.
|
|
|
|

|
|
|
|
LangChain streamlines these stages (in figure above) by providing pre-built components and tools for integration, memory management, and deployment, allowing developers to focus on application logic rather than underlying complexities.
|
|
|
|
Integration of **Langchain** with **LanceDB** enables applications to retrieve the most relevant data by comparing query vectors against stored vectors, facilitating effective information retrieval. It results in better and context aware replies and actions by the LLMs.
|
|
|
|
## Quick Start {#quick-start}
|
|
You can load your document data using langchain's loaders, for this example we are using `TextLoader` and `OpenAIEmbeddings` as the embedding model.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainQuickStart}
|
|
</CodeBlock>
|
|
|
|
## Documentation {#documentation}
|
|
In the above example `LanceDB` vector store class object is created using `from_documents()` method which is a `classmethod` and returns the initialized class object.
|
|
|
|
You can also use `LanceDB.from_texts(texts: List[str],embedding: Embeddings)` class method.
|
|
|
|
The exhaustive list of parameters for `LanceDB` vector store are :
|
|
|
|
|Name|type|Purpose|default|
|
|
|:----|:----|:----|:----|
|
|
|`connection`| (Optional) `Any` |`lancedb.db.LanceDBConnection` connection object to use. If not provided, a new connection will be created.|`None`|
|
|
|`embedding`| (Optional) `Embeddings` | Langchain embedding model.|Provided by user.|
|
|
|`uri`| (Optional) `str` |It specifies the directory location of **LanceDB database** and establishes a connection that can be used to interact with the database. |`/tmp/lancedb`|
|
|
|`vector_key` |(Optional) `str`| Column name to use for vector's in the table.|`'vector'`|
|
|
|`id_key` |(Optional) `str`| Column name to use for id's in the table.|`'id'`|
|
|
|`text_key` |(Optional) `str` |Column name to use for text in the table.|`'text'`|
|
|
|`table_name` |(Optional) `str`| Name of your table in the database.|`'vectorstore'`|
|
|
|`api_key` |(Optional `str`) |API key to use for LanceDB Enterprise deployment.|`None`|
|
|
|`region` |(Optional) `str`| Region to use for LanceDB Enterprise deployment.| Only for LanceDB Enterprise : `None`.|
|
|
|`mode` |(Optional) `str` | Mode to use for adding data to the table. Valid values are "append" and "overwrite".|`'overwrite'`|
|
|
|`table`| (Optional) `Any`| You can connect to an existing table of LanceDB, created outside of langchain, and utilize it.|`None`|
|
|
|`distance`|(Optional) `str`| The choice of distance metric used to calculate the similarity between vectors.|`'l2'`|
|
|
|`reranker` |(Optional) `Any`| The reranker to use for LanceDB.|`None`|
|
|
|`relevance_score_fn` |(Optional) `Callable[[float], float]` | Langchain relevance score function to be used.|`None`|
|
|
|`limit`|`int`|Set the maximum number of results to return.| `DEFAULT_K` (it is 4)|
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainVectorStoreConfig}
|
|
</CodeBlock>
|
|
|
|
### Methods {#methods}
|
|
|
|
##### `add_texts()`
|
|
|
|
This method turn texts into embedding and add it to the database.
|
|
|
|
|Name|Purpose|defaults|
|
|
|:---|:---|:---|
|
|
|`texts`|`Iterable` of strings to add to the vectorstore.|Provided by user|
|
|
|`metadatas`|Optional `list[dict()]` of metadatas associated with the texts.|`None`|
|
|
|`ids`|Optional `list` of ids to associate with the texts.|`None`|
|
|
|`kwargs`| Other keyworded arguments provided by the user. |-|
|
|
|
|
It returns list of ids of the added texts.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainAddTexts}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
|
|
##### create_index()
|
|
|
|
This method creates a scalar(for non-vector cols) or a vector index on a table.
|
|
|
|
|Name|type|Purpose|defaults|
|
|
|:---|:---|:---|:---|
|
|
|`vector_col`|`Optional[str]`| Provide if you want to create index on a vector column. |`None`|
|
|
|`col_name`|`Optional[str]`| Provide if you want to create index on a non-vector column. |`None`|
|
|
|`metric`|`Optional[str]` |Provide the metric to use for vector index. choice of metrics: 'l2', 'dot', 'cosine'. |`l2`|
|
|
|`num_partitions`|`Optional[int]`|Number of partitions to use for the index.|`256`|
|
|
|`num_sub_vectors`|`Optional[int]` |Number of sub-vectors to use for the index.|`96`|
|
|
|`index_cache_size`|`Optional[int]` |Size of the index cache.|`None`|
|
|
|`name`|`Optional[str]` |Name of the table to create index on.|`None`|
|
|
|
|
For index creation make sure your table has enough data in it. An ANN index is usually not needed for datasets ~100K vectors. For large-scale (>1M) or higher dimension vectors, it is beneficial to create an ANN index.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainCreateIndex}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### similarity_search()
|
|
|
|
This method performs similarity search based on **text query**.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|---------|----------------------|---------|---------|
|
|
| `query` | `str` | A `str` representing the text query that you want to search for in the vector store. | N/A |
|
|
| `k` | `Optional[int]` | It specifies the number of documents to return. | `None` |
|
|
| `filter` | `Optional[Dict[str, str]]`| It is used to filter the search results by specific metadata criteria. | `None` |
|
|
| `fts` | `Optional[bool]` | It indicates whether to perform a full-text search (FTS). | `False` |
|
|
| `name` | `Optional[str]` | It is used for specifying the name of the table to query. If not provided, it uses the default table set during the initialization of the LanceDB instance. | `None` |
|
|
| `kwargs` | `Any` | Other keyworded arguments provided by the user. | N/A |
|
|
|
|
Return documents most similar to the query **without relevance scores**.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainSimilaritySearch}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### similarity_search_by_vector()
|
|
|
|
The method returns documents that are most similar to the specified **embedding (query) vector**.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|-------------|---------------------------|---------|---------|
|
|
| `embedding` | `List[float]` | The embedding vector you want to use to search for similar documents in the vector store. | N/A |
|
|
| `k` | `Optional[int]` | It specifies the number of documents to return. | `None` |
|
|
| `filter` | `Optional[Dict[str, str]]`| It is used to filter the search results by specific metadata criteria. | `None` |
|
|
| `name` | `Optional[str]` | It is used for specifying the name of the table to query. If not provided, it uses the default table set during the initialization of the LanceDB instance. | `None` |
|
|
| `kwargs` | `Any` | Other keyworded arguments provided by the user. | N/A |
|
|
|
|
**It does not provide relevance scores.**
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainSimilaritySearchByVector}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### similarity_search_with_score()
|
|
|
|
Returns documents most similar to the **query string** along with their relevance scores.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|----------|---------------------------|---------|---------|
|
|
| `query` | `str` |A `str` representing the text query you want to search for in the vector store. This query will be converted into an embedding using the specified embedding function. | N/A |
|
|
| `k` | `Optional[int]` | It specifies the number of documents to return. | `None` |
|
|
| `filter` | `Optional[Dict[str, str]]`| It is used to filter the search results by specific metadata criteria. This allows you to narrow down the search results based on certain metadata attributes associated with the documents. | `None` |
|
|
| `kwargs` | `Any` | Other keyworded arguments provided by the user. | N/A |
|
|
|
|
It gets called by base class's `similarity_search_with_relevance_scores` which selects relevance score based on our `_select_relevance_score_fn`.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainSimilaritySearchWithScores}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### similarity_search_by_vector_with_relevance_scores()
|
|
|
|
Similarity search using **query vector**.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|-------------|---------------------------|---------|---------|
|
|
| `embedding` | `List[float]` | The embedding vector you want to use to search for similar documents in the vector store. | N/A |
|
|
| `k` | `Optional[int]` | It specifies the number of documents to return. | `None` |
|
|
| `filter` | `Optional[Dict[str, str]]`| It is used to filter the search results by specific metadata criteria. | `None` |
|
|
| `name` | `Optional[str]` | It is used for specifying the name of the table to query. | `None` |
|
|
| `kwargs` | `Any` | Other keyworded arguments provided by the user. | N/A |
|
|
|
|
The method returns documents most similar to the specified embedding (query) vector, along with their relevance scores.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainSimilaritySearchByVectorWithScores}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### max_marginal_relevance_search()
|
|
|
|
This method returns docs selected using the maximal marginal relevance(MMR).
|
|
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|---------------|-----------------|-----------|---------|
|
|
| `query` | `str` | Text to look up documents similar to. | N/A |
|
|
| `k` | `Optional[int]` | Number of Documents to return.| `4` |
|
|
| `fetch_k`| `Optional[int]`| Number of Documents to fetch to pass to MMR algorithm.| `None` |
|
|
| `lambda_mult` | `float` | Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. | `0.5` |
|
|
| `filter`| `Optional[Dict[str, str]]`| Filter by metadata. | `None` |
|
|
|`kwargs`| Other keyworded arguments provided by the user. |-|
|
|
|
|
Similarly, `max_marginal_relevance_search_by_vector()` function returns docs most similar to the embedding passed to the function using MMR. instead of a string query you need to pass the embedding to be searched for.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainMaxMarginalRelevance}
|
|
</CodeBlock>
|
|
|
|
------
|
|
|
|
##### add_images()
|
|
|
|
This method adds images by automatically creating their embeddings and adds them to the vectorstore.
|
|
|
|
| Name | Type | Purpose | Default |
|
|
|------------|-------------------------------|--------------------------------|---------|
|
|
| `uris` | `List[str]` | File path to the image | N/A |
|
|
| `metadatas`| `Optional[List[dict]]` | Optional list of metadatas | `None` |
|
|
| `ids` | `Optional[List[str]]` | Optional list of IDs | `None` |
|
|
|
|
It returns list of IDs of the added images.
|
|
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyFrameworksLangchainAddImages}
|
|
</CodeBlock>
|
|
|
|
|