💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Add graph documentation, closes #343
davidmezzetti0a23cbd88a19
diff --git a/README.md b/README.mdindex e63d7c8f..92159358 100644--- a/README.md+++ b/README.md@@ -106,7 +106,9 @@ curl -X GET "http://localhost:8000/search?query=positive"The easiest way to install is via pip and PyPI- pip install txtai+```+pip install txtai+```Python 3.7+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.diff --git a/docs/api/configuration.md b/docs/api/configuration.mdindex 22abe3bb..c702cfbd 100644--- a/docs/api/configuration.md+++ b/docs/api/configuration.md@@ -36,7 +36,7 @@ writable: booleanDetermines if the input embeddings index is writable (true) or read-only (false). This allows serving a read-only index.### cloud-[Cloud storage settings](../../embeddings/configuration#cloud) can be set under a `cloud` top level configuration group.+[Cloud storage settings](../../embeddings/configuration/cloud) can be set under a `cloud` top level configuration group.## Pipelinediff --git a/docs/embeddings/configuration/cloud.md b/docs/embeddings/configuration/cloud.mdnew file mode 100644index 00000000..33924857--- /dev/null+++ b/docs/embeddings/configuration/cloud.md@@ -0,0 +1,59 @@+# Cloud++This section describes parameters used to sync compressed indexes with cloud storage. These parameters are only enabled if an embeddings index is stored as compressed. They are set via the [embeddings.load](../../methods/#txtai.embeddings.base.Embeddings.load) and [embeddings.save](../../methods/#txtai.embeddings.base.Embeddings.save) methods.++## provider+```yaml+provider: string+```++The cloud storage provider, see [full list of providers here](https://libcloud.readthedocs.io/en/stable/storage/supported_providers.html).++## container+```yaml+container: string+```++Container/bucket/directory name.++## key+```yaml+key: string+```++Provider-specific access key. Can also be set via ACCESS_KEY environment variable. Ensure the configuration file is secured if added to the file.++## secret+```yaml+secret: string+```++Provider-specific access secret. Can also be set via ACCESS_SECRET environment variable. Ensure the configuration file is secured if added to the file.++## host+```yaml+host: string+```++Optional server host name. Set when using a local cloud storage server.++## port+```yaml+port: int+```++Optional server port. Set when using a local cloud storage server.++## token+```yaml+token: string+```++Optional temporary session token++## region+```yaml+region: string+```++Optional parameter to specify the storage region, provider-specific.diff --git a/docs/embeddings/configuration.md b/docs/embeddings/configuration/index.mdsimilarity index 73%rename from docs/embeddings/configuration.mdrename to docs/embeddings/configuration/index.mdindex ec5fed9f..7b328080 100644--- a/docs/embeddings/configuration.md+++ b/docs/embeddings/configuration/index.md@@ -1,9 +1,8 @@# Configuration-## EmbeddingsThis following describes available embeddings configuration. These parameters are set via the [Embeddings constructor](../methods#txtai.embeddings.base.Embeddings.__init__).-### path+## path```yamlpath: string```@@ -11,7 +10,7 @@ path: stringSets the path for a vectors model. When using a transformers/sentence-transformers model, this can be any model on the[Hugging Face Model Hub](https://huggingface.co/models) or a local file path. Otherwise, it must be a local file path to a word embeddings model.-### method+## method```yamlmethod: transformers|sentence-transformers|words|external```@@ -20,76 +19,84 @@ Sentence embeddings method to use. If the method is not provided, it is inferred`sentence-transformers` and `words` require the [similarity](../../install/#similarity) extras package to be installed.-#### transformers+### transformersBuilds sentence embeddings using a transformers model. While this can be any transformers model, it works best with[models trained](https://huggingface.co/models?pipeline_tag=sentence-similarity) to build sentence embeddings.-#### sentence-transformers+### sentence-transformersSame as transformers but loads models with the [sentence-transformers](https://github.com/UKPLab/sentence-transformers) library.-#### words+### wordsBuilds sentence embeddings using a word embeddings model. Transformers models are the preferred vector backend in most cases. Word embeddings models may be deprecated in the future.-##### storevectors+#### storevectors```yamlstorevectors: boolean```Enables copying of a vectors model set in path into the embeddings models output directory on save. This option enables a fully encapsulated index with no external file dependencies.-##### scoring+#### scoring```yamlscoring: bm25|tfidf|sif```A scoring model builds weighted averages of word vectors for a given sentence. Supports BM25, TF-IDF and SIF (smooth inverse frequency) methods. If a scoring method is not provided, mean sentence embeddings are built.-##### pca+#### pca```yamlpca: int```Removes _n_ principal components from generated sentence embeddings. When enabled, a TruncatedSVD model is built to help with dimensionality reduction. After pooling of vectors creates a single sentence embedding, this method is applied.-#### external+### externalSentence embeddings are loaded via an external model or API. Requires setting the [transform](#transform) parameter to a function that translates data into vectors.-##### transform+#### transform```yamltransform: function```When method is `external`, this function transforms input content into embeddings. The input to this function is a list of data. This method must return either a numpy array or list of numpy arrays.-### batch+## batch```yamlbatch: int```Sets the transform batch size. This parameter controls how input streams are chunked and vectorized.-### encodebatch+## encodebatch```yamlencodebatch: int```Sets the encode batch size. This parameter controls the underlying vector model batch size. This often corresponds to a GPU batch size, which controls GPU memory usage.-### backend+## tokenize+```yaml+tokenize: boolean+```++Enables string tokenization (defaults to false). This method applies tokenization rules that only work with English language text and may increase the quality of+English language sentence embeddings in some situations.++## backend```yamlbackend: faiss|hnsw|annoy```-Approximate Nearest Neighbor (ANN) index backend for storing generated sentence embeddings. `Defaults to Faiss`. Additional backends require the+Approximate Nearest Neighbor (ANN) index backend for storing generated sentence embeddings. `Defaults to faiss`. Additional backends require the[similarity](../../install/#similarity) extras package to be installed.Backend-specific settings are set with a corresponding configuration object having the same name as the backend (i.e. annoy, faiss, or hnsw). None of these are required and are set to defaults if omitted.-#### faiss+### faiss```yamlfaiss:components: comma separated list of components - defaults to "Flat" for small@@ -110,18 +117,18 @@ See the following Faiss documentation links for more information.- [Index Factory](https://github.com/facebookresearch/faiss/wiki/The-index-factory)- [Search Tuning](https://github.com/facebookresearch/faiss/wiki/Faster-search)-#### hnsw+### hnsw```yamlhnsw:efconstruction: ef_construction param for init_index (int) - defaults to 200m: M param for init_index (int) - defaults to 16- randomseed: random-seed param for init_index (init) - defaults to 100+ randomseed: random-seed param for init_index (int) - defaults to 100efsearch: ef search param (int) - defaults to None and not set```See [Hnswlib documentation](https://github.com/nmslib/hnswlib/blob/master/ALGO_PARAMS.md) for more information on these parameters.-#### annoy+### annoy```yamlannoy:ntrees: number of trees (int) - defaults to 10@@ -130,14 +137,14 @@ annoy:See [Annoy documentation](https://github.com/spotify/annoy#full-python-api) for more information on these parameters. Note that annoy indexes can not be modified after creation, upserts/deletes and other modifications are not supported.-### content+## content```yamlcontent: string|boolean```Enables content storage. When true, the default content storage engine will be used. Otherwise, the string must specify the supported content storage engine to use.-### functions+## functions```yamlfunctions: list```@@ -150,7 +157,7 @@ List of functions with user-defined SQL functions, only used when [content](#con[An example can be found here](../query#custom-sql-functions).-### query+## query```yamlquery:path: sets the path for the query model - this can be any model on the@@ -161,70 +168,38 @@ query:Query translation model. Translates natural language queries to txtai compatible SQL statements.-### tokenize-```yaml-tokenize: boolean-```--Enables string tokenization (defaults to false). This method applies tokenization rules that only work with English language text and may increase the quality of-English language sentence embeddings in some situations.--## Cloud--This section describes parameters used to sync compressed indexes with cloud storage. These parameters are only enabled if an embeddings index is stored as compressed. They are set via the [embeddings.load](../methods/#txtai.embeddings.base.Embeddings.load) and [embeddings.save](../methods/#txtai.embeddings.base.Embeddings.save) methods.--### provider-```yaml-provider: string-```--The cloud storage provider, see [full list of providers here](https://libcloud.readthedocs.io/en/stable/storage/supported_providers.html).--### container+## graph```yaml-container: string+graph:+ backend: graph network backend (string), defaults to "networkx"+ batchsize: batch query size, used to query embeddings index (int)+ defaults to 256+ limit: maximum number of results to return per embeddings query (int)+ defaults to 15+ minscore: minimum score required to consider embeddings query matches (float)+ defaults to 0.1+ approximate: when true, queries only run for nodes without edges (boolean)+ defaults to true+ topics: see below```-Container/bucket/directory name.--### key-```yaml-key: string-```--Provider-specific access key. Can also be set via ACCESS_KEY environment variable. Ensure the configuration file is secured if added to the file.--### secret-```yaml-secret: string-```--Provider-specific access secret. Can also be set via ACCESS_SECRET environment variable. Ensure the configuration file is secured if added to the file.--### host-```yaml-host: string-```--Optional server host name. Set when using a local cloud storage server.--### port-```yaml-port: int-```--Optional server port. Set when using a local cloud storage server.--### token-```yaml-token: string-```+Enables graph storage. When set, a graph network is built using the embeddings index. Graph nodes are synced with each embeddings index operation (index/upsert/delete). Graph edges are created using the embeddings index upon completion of each index/upsert/delete embeddings index call.-Optional temporary session token+Defaults are tuned so that in most cases these values don't need to be changed.-### region+### topics```yaml-region: string+topics:+ algorithm: community detection algorithm (string), options are+ louvain (default), greedy, lpa+ level: controls number of topics (string), options are best (default) or first+ resolution: controls number of topics (int), larger values create more+ topics (int), defaults to 100+ labels: scoring index method used to build topic labels (string)+ options are bm25 (default), tfidf, sif+ terms: number of frequent terms to use for topic labels (int), defaults to 4+ categories: optional list of categories used to group topics, allows+ granular topics with broad categories grouping topics```-Optional parameter to specify the storage region, provider-specific.+Enables topic modeling. Defaults are tuned so that in most cases these values don't need to be changed (except for categories). These parameters are available for advanced use cases where one wants full control over the community detection process.diff --git a/docs/embeddings/indexing.md b/docs/embeddings/indexing.mdindex 7b0aab5f..c829fd07 100644--- a/docs/embeddings/indexing.md+++ b/docs/embeddings/indexing.md@@ -43,7 +43,7 @@ Compressed indexes are also supported.embeddings.save("/path/to/save/index.tar.gz")```-In addition to saving indexes locally, they can also be persisted to [cloud storage](../configuration#cloud).+In addition to saving indexes locally, they can also be persisted to [cloud storage](../configuration/cloud).```pythonembeddings.save("/path/to/save/index.tar.gz", cloud={...})@@ -73,6 +73,30 @@ When [content storage](../configuration#content) is enabled, [reindex](../methodembeddings.reindex({"path": "sentence-transformers/all-MiniLM-L6-v2", "backend": "hnsw"})```+## Graph++Enabling a [graph network](../configuration#graph) adds the ability to run topic modeling and analyze data connectivity. Graphs are synchronized with the main embeddings index.++Get a mapping of discovered topics to associated ids.++```python+embeddings.graph.topics+```++Show the most central nodes in the index.++```python+embeddings.graph.centrality()+```++Show how node 1 and node 2 are connected in the graph.++```python+embeddings.graph.showpath(id1, id2)+```++Graphs are persisted alongside an embeddings index. Each save and load will also save and load the graph.+## ScoringWhen using [word vector backed models](../configuration#words) with scoring set, a separate call is required before calling `index` as follows:diff --git a/docs/embeddings/methods.md b/docs/embeddings/methods.mdindex 7cdb6df9..66c81423 100644--- a/docs/embeddings/methods.md+++ b/docs/embeddings/methods.md@@ -3,8 +3,10 @@::: txtai.embeddings.Embeddingsselection:filters:+ - "!createdatabase"+ - "!creategraph"- "!checkarchive"- "!configure"- - "!createdatabase"+ - "!loadquery"- "!loadvectors"- "!normalize"diff --git a/docs/install.md b/docs/install.mdindex e77ecca7..acc37c0f 100644--- a/docs/install.md+++ b/docs/install.md@@ -5,7 +5,9 @@The easiest way to install is via pip and PyPI- pip install txtai+```+pip install txtai+```Python 3.7+ is supported. Using a Python [virtual environment](https://docs.python.org/3/library/venv.html) is recommended.@@ -16,7 +18,7 @@ in setup.py install_requires sections.### All-Install all dependencies (mirrors txtai < 3.2)+Install all dependencies (mirrors txtai < 3.2).```pip install txtai[all]@@ -38,17 +40,33 @@ Interface with cloud compute.pip install txtai[cloud]```+### Console++Command line index query console.++```+pip install txtai[console]+```+### Database-Additional content storage options+Additional content storage options.```pip install txtai[database]```+### Graph++Topic modeling, data connectivity and network analysis.++```+pip install txtai[graph]+```+### Model-Additional non-standard models+Additional non-standard models.```pip install txtai[model]diff --git a/mkdocs.yml b/mkdocs.ymlindex 68808dae..ef4fb870 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -51,7 +51,9 @@ nav:- Examples: examples.md- Embeddings:- embeddings/index.md- - Configuration: embeddings/configuration.md+ - Configuration:+ - embeddings/configuration/index.md+ - Cloud: embeddings/configuration/cloud.md- Index Guide: embeddings/indexing.md- Methods: embeddings/methods.md- Query Guide: embeddings/query.md