Metadata-Version: 2.4
Name: sinapsis-llama-index
Version: 0.3.1
Summary: Sinapsis templates for LlamaIndex retrieval and ingestion.
Author-email: SinapsisAI <dev@sinapsis.tech>
Project-URL: Homepage, https://sinapsis.tech
Project-URL: Documentation, https://docs.sinapsis.tech/docs
Project-URL: Tutorials, https://docs.sinapsis.tech/tutorials
Project-URL: Repository, https://github.com/Sinapsis-AI/sinapsis-chatbots.git
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-core>=1.0.0
Requires-Dist: llama-index>=0.12.25
Requires-Dist: llama-index-embeddings-huggingface>=0.5.2
Requires-Dist: llama-index-vector-stores-postgres>=0.4.2
Requires-Dist: psycopg>=3.2.12
Requires-Dist: sinapsis>=0.2.26
Requires-Dist: sinapsis-chatbots-base[torch]
Requires-Dist: tree-sitter-language-pack>=0.8.0
Dynamic: license-file

<h1 align="center">
<br>
<a href="https://sinapsis.tech/">
  <img
    src="https://github.com/Sinapsis-AI/brand-resources/blob/main/sinapsis_logo/4x/logo.png?raw=true"
    alt="" width="300">
</a>
<br>
Sinapsis LlamaIndex
<br>
</h1>

<h4 align="center">Sinapsis templates for LlamaIndex ingestion, retrieval, reranking, and semantic caching.</h4>

<p align="center">
<a href="#installation">🐍 Installation</a> •
<a href="#features">🚀 Features</a> •
<a href="#example">📚 Usage example</a> •
<a href="#documentation">📙 Documentation</a> •
<a href="#license">🔍 License</a>
</p>

The `sinapsis-llama-index` package provides ingestion, retrieval, reranking, and semantic caching templates built on top of [LlamaIndex](https://github.com/run-llama/llama_index). It is designed to work with Sinapsis packet flows, including plain `TextPacket` retrieval and `LLMConversationPacket.contexts` for downstream LLM templates.

<h2 id="installation">🐍 Installation</h2>

Install using your package manager of choice. We encourage the use of <code>uv</code>.

Example with <code>uv</code>:

```bash
uv pip install sinapsis-llama-index --extra-index-url https://pypi.sinapsis.tech
```

or with raw <code>pip</code>:

```bash
pip install sinapsis-llama-index --extra-index-url https://pypi.sinapsis.tech
```

<h2 id="features">🚀 Features</h2>

<h3> Templates Supported</h3>

* `EmbeddingNodeGenerator`: Split text documents into chunks and generate embedded `TextNode` objects.
* `CodeEmbeddingNodeGenerator`: Split source-code repositories with `CodeSplitter` and embed the resulting nodes.
* `LLaMAIndexInsertNodes`: Insert embedded nodes into PostgreSQL `PGVectorStore` tables.
* `LLaMAIndexNodeRetriever`: Retrieve nodes from PGVector for both `TextPacket` and `LLMConversationPacket` inputs.
* `LLaMAIndexReranker`: Rerank selected `LLMConversationPacket.contexts` categories with
  `SentenceTransformerRerank`.
* `LLaMAIndexSemanticCacheLookup`: Reuse cached LLM responses from PGVector when a semantically similar prompt is found under the same request scope.
* `LLaMAIndexSemanticCacheWrite`: Persist completed LLM responses into a PGVector-backed semantic cache for future reuse.
* `LLaMAIndexClearTable`: Clear all rows from a PGVector table while keeping its schema.
* `LLaMAIndexDeleteTable`: Drop a PGVector table and remove all stored vectors.

> [!TIP]
> Use CLI command ``` sinapsis info --all-template-names``` to show a list with all the available Template names installed with Sinapsis Chatbots Base.

<h2 id="example">📚 Usage example</h2>

The following configuration assumes a PGVector table is already populated and shows a typical retrieval pipeline:
create an `LLMConversationPacket`, retrieve candidate contexts from PGVector, and rerank them before a downstream LLM template consumes the results.

<details id='usage'><summary><strong><span style="font-size: 1.0em;"> Config</span></strong></summary>

```yaml
agent:
  name: reranker_demo
  description: Retrieve and rerank help-center contexts before they are consumed by an LLM.

templates:
  - template_name: InputTemplate
    class_name: InputTemplate
    attributes: {}

  - template_name: LLMConversationInput
    class_name: LLMConversationInput
    template_input: InputTemplate
    attributes:
      prompt: "How long does the password reset link remain valid?"
      system_prompt: "Use the best retrieved context."

  - template_name: LLaMAIndexNodeRetriever
    class_name: LLaMAIndexNodeRetriever
    template_input: LLMConversationInput
    attributes:
      embedding_config:
        model_name: Snowflake/snowflake-arctic-embed-xs
        embed_batch_size: 10
        device: cpu
        trust_remote_code: true
      db_config:
        user: myuser
        password: mypass
        port: 5432
        host: localhost
        db_name: sinapsis_db
        table_name: sinapsis_data
      retrieve_args:
        query_mode: default
        similarity_top_k: 8
        threshold: 0.3

  - template_name: LLaMAIndexReranker
    class_name: LLaMAIndexReranker
    template_input: LLaMAIndexNodeRetriever
    attributes:
      rerank_config:
        model: cross-encoder/stsb-distilroberta-base
        top_n: 2
        device: cpu
        keep_retrieval_score: false
        trust_remote_code: true
      rerank_categories:
        - rag
```

</details>

<h2 id="documentation">📙 Documentation</h2>

Documentation for this and other sinapsis packages is available on the [sinapsis website](https://docs.sinapsis.tech/docs)

Tutorials for different projects within sinapsis are available at [sinapsis tutorials page](https://docs.sinapsis.tech/tutorials)

<h2 id="license">🔍 License</h2>

This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the [LICENSE](LICENSE) file.

For commercial use, please refer to our [official Sinapsis website](https://sinapsis.tech) for information on obtaining a commercial license.
