Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,78 +32,18 @@ pip install zep-cloud
> [!NOTE]
> Zep Cloud [overview](https://help.getzep.com/concepts) and [cloud sdk guide](https://help.getzep.com/sdks).

### Community Installation
```bash
pip install zep-python
```
> [!NOTE]
> Zep Community Edition [quick start](https://help.getzep.com/ce/quickstart) and [sdk guide](https://help.getzep.com/ce/sdks).

### Zep v0.x Compatible SDK
You can install Zep v0.x compatible sdk by running:
```bash
pip install "zep-python>=1.5.0,<2.0.0"
```
> [!NOTE]
> Zep v0.x [quick start](https://help.getzep.com/ce/legacy/deployment/quickstart) and [sdk guide](https://help.getzep.com/ce/legacy/sdk).

### How Zep works

Zep persists and recalls chat histories, and automatically generates summaries and other artifacts from these chat histories. It also embeds messages and summaries, enabling you to search Zep for relevant context from past conversations. Zep does all of this asynchronously, ensuring these operations don't impact your user's chat experience. Data is persisted to database, allowing you to scale out when growth demands.

Zep also provides a simple, easy to use abstraction for document vector search called Document Collections. This is designed to complement Zep's core context features, but is not designed to be a general purpose vector database.

Zep allows you to be more intentional about constructing your prompt:
1. automatically adding a few recent messages, with the number customized for your app;
2. a summary of recent conversations prior to the messages above;
3. and/or contextually relevant summaries or messages surfaced from the entire chat session.
4. and/or relevant Business data from Zep Document Collections.

Zep Cloud offers:
- **Fact Extraction:** Automatically build fact tables from conversations, without having to define a data schema upfront.
- **Dialog Classification:** Instantly and accurately classify chat dialog. Understand user intent and emotion, segment users, and more. Route chains based on semantic context, and trigger events.
- **Structured Data Extraction:** Quickly extract business data from chat conversations using a schema you define. Understand what your Assistant should ask for next in order to complete its task.

You will also need to provide a Zep Project API key to your zep client.
You can find out about zep projects in our [cloud docs](https://help.getzep.com/projects.html)

### Using LangChain Zep Classes with `zep-python`

(Currently only available on release candidate versions)

In the pre-release version `zep-python` sdk comes with `ZepChatMessageHistory` and `ZepVectorStore`
classes that are compatible with [LangChain's Python expression language](https://python.langchain.com/docs/expression_language/)

In order to use these classes in your application, you need to make sure that you have
`langchain_core` package installed, please refer to [Langchain's docs installation section](https://python.langchain.com/docs/get_started/installation#langchain-core).

We support `langchain_core@>=0.1.3<0.2.0`

You can import these classes in the following way:

```python
from zep_cloud.langchain import ZepChatMessageHistory, ZepVectorStore
```

### Running Examples
You will need to set the following environment variables to run examples in the `examples` directory:

```dotenv
# Please use examples/.env.example as a template for .env file

# Required
ZEP_API_KEY=<zep-project-api-key># Your Zep Project API Key
ZEP_COLLECTION=<zep-collection-name># used in ingestion script and in vector store examples
OPENAI_API_KEY=<openai-api-key># Your OpenAI API Key

# Optional (If you want to use langsmith with LangServe Sample App)
LANGCHAIN_TRACING_V2=true
LANGCHAIN_API_KEY=<your-langchain-api-key>
LANGCHAIN_PROJECT=<your-langchain-project-name># If not specified, defaults to "default"
```



## Installation

```sh
Expand Down
19 changes: 19 additions & 0 deletions src/zep_cloud/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TraveledTo(EdgeModel):
"EntityFloat",
"EntityBoolean",
"Identity",
"Excluded",
"PropertyType",
"build_ontology",
]
Expand All @@ -88,6 +89,18 @@ class _Identity:
Identity = _Identity()


class _Excluded:
"""Marks a field as left out of the ontology entirely."""


# Annotate a field with this to leave it out of the ontology, regardless of
# whether it also carries a property type marker. This is what lets a model
# reused for other purposes, such as one already shaped by another schema,
# keep a field that is not an ontology property instead of having to be split
# into a separate class just for that field.
Excluded = _Excluded()


# The four property types the API accepts. Declared once: a change to the wire
# spelling is a change here and nowhere else.
EntityText = Annotated[typing.Optional[str], PropertyType("text")]
Expand Down Expand Up @@ -132,6 +145,8 @@ def _properties(
properties: typing.List[EntityProperty] = []
identity_properties: typing.List[str] = []
for name, field in model.model_fields.items():
if any(isinstance(m, _Excluded) for m in field.metadata):
continue
marker = next(
(m for m in field.metadata if isinstance(m, PropertyType)),
None,
Expand Down Expand Up @@ -161,6 +176,10 @@ def build_ontology(
) -> typing.Tuple[typing.List[EntityType], typing.List[EdgeType]]:
"""Derive the entity and edge type lists from the given model classes.

Every field needs a property type marker (``EntityText``, ``EntityInt``,
``EntityFloat``, or ``EntityBoolean``), unless it is annotated with
``Excluded``, which leaves it out of the ontology entirely.

Pass the result to ``graph.set_ontology`` for one graph, or to
``project.set_ontology`` for the project default. v3 addressed many graphs in
one call; v4 has one ontology endpoint per scope, so a caller targeting
Expand Down
41 changes: 41 additions & 0 deletions tests/ontology/test_build_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
EntityInt,
EntityModel,
EntityText,
Excluded,
Identity,
build_ontology,
)
Expand Down Expand Up @@ -145,6 +146,46 @@ class Bad(EntityModel):
build_ontology(entities={"Bad": Bad})


def test_an_excluded_field_is_left_out_of_the_ontology():
# A model reused for something other than the ontology can carry a field
# that is not a property, the same way Go's `zep:"-"` struct tag lets a
# struct field opt out.
class Place(EntityModel):
"""A place."""

country: EntityText = Field(default=None, description="Its country")
internal_id: Annotated[str, Excluded] = "unused"

entity_types, _ = build_ontology(entities={"Place": Place})
assert [p.name for p in entity_types[0].properties] == ["country"]


def test_an_excluded_field_with_no_description_still_builds():
# Excluded means the field is never read as a property at all, so it
# cannot be rejected for missing a description either.
class Place(EntityModel):
"""A place."""

country: EntityText = Field(default=None, description="Its country")
internal_id: Annotated[str, Excluded] = "unused"

entity_types, _ = build_ontology(entities={"Place": Place})
assert len(entity_types[0].properties) == 1


def test_an_unmarked_field_alongside_an_excluded_one_is_still_rejected():
# Excluded opts a specific field out; it does not relax the requirement
# for every other field to carry a property type marker.
class Bad(EntityModel):
"""Has one excluded field and one that is still unmarked."""

internal_id: Annotated[str, Excluded] = "unused"
oops: str = "x"

with pytest.raises(ValueError, match="Bad.oops is not an ontology property"):
build_ontology(entities={"Bad": Bad})


def test_a_property_with_no_description_is_rejected_by_name():
# The description goes into the extraction prompt; an empty one is accepted
# by the write path and quietly degrades extraction.
Expand Down
Loading