PiyAPI LangChain Adapter
A LangChain VectorStore adapter for PiyAPI Memory, enabling seamless integration with LangChain applications.
PiyAPI by Negentro is the memory layer for AI agents: 84.1% on BEAM-1M, 93.6% on LongMemEval-S and 97% fewer tokens than the full history, with every answer published. Start for free · Docs · Benchmarks
Installation
pip install piyapi-langchain
Quick Start
from piyapi_langchain import PiyAPIVectorStore
from langchain_openai import OpenAIEmbeddings
# Initialize the vector store
vectorstore = PiyAPIVectorStore(
api_key="your-api-key",
namespace="my-app",
embedding=OpenAIEmbeddings()
)
# Add documents
from langchain_core.documents import Document
docs = [
Document(page_content="PiyAPI Memory is a vector database", metadata={"source": "docs"}),
Document(page_content="LangChain enables AI applications", metadata={"source": "docs"}),
]
vectorstore.add_documents(docs)
# Search
results = vectorstore.similarity_search("vector database", k=5)
for doc in results:
print(doc.page_content)
# Search with scores
results_with_scores = vectorstore.similarity_search_with_score("AI applications", k=5)
for doc, score in results_with_scores:
print(f"{doc.page_content} (score: {score})")
Using as a Retriever
# Create a retriever
retriever = vectorstore.as_retriever(
search_type="similarity",
search_kwargs={"k": 5}
)
# Use in a chain
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser
def format_docs(docs):
# One block, in retrieval order, text only: no scores or metadata that change between calls.
return "\n\n".join(doc.page_content for doc in docs)
# from_template makes a single human message, so the memories land in the user turn.
template = """Answer based on the context:
{context}
Question: {question}
"""
prompt = ChatPromptTemplate.from_template(template)
llm = ChatOpenAI()
chain = (
{"context": retriever | format_docs, "question": RunnablePassthrough()}
| prompt
| llm
| StrOutputParser()
)
answer = chain.invoke("What is PiyAPI Memory?")
In a multi-turn chain, keep the system message fixed, put {context} in the newest human message
only (after a MessagesPlaceholder for the history), and store each earlier human message in the
history exactly as it was sent, context included. Never put the context in the system message.
Metadata Filtering
# Filter by metadata
results = vectorstore.similarity_search(
"vector database",
k=5,
filter={"source": "docs"}
)
Configuration
| Parameter | Type | Required | Description |
|---|---|---|---|
api_key |
str | Yes | Your PiyAPI API key |
namespace |
str | No | Namespace for organizing memories (default: "default") |
embedding |
Embeddings | No | LangChain embedding function (uses PiyAPI embeddings if not provided) |
base_url |
str | No | Custom API base URL |
LangGraph store
PiyAPIStore is a LangGraph BaseStore (batch/abatch with Get, Put, Search and ListNamespaces operations).
Each item is one PiyAPI memory file, /memories/langgraph/<namespace labels>/<key>.json, holding the value as
JSON: versioned, soft-deleted, and searchable. search(..., query=...) uses PiyAPI hybrid search under the
namespace prefix; without a query it lists the items. Filters, offset/limit and list_namespaces
(prefix, suffix, *, max_depth) behave as in LangGraph's InMemoryStore. index and ttl are accepted and
ignored (every item is searchable; items do not expire). Requires langgraph (install it yourself).
from piyapi_memory import PiyAPIClient, AsyncPiyAPIClient
from piyapi_langchain.store import PiyAPIStore
store = PiyAPIStore(PiyAPIClient(), namespace="my-app", async_client=AsyncPiyAPIClient())
graph = builder.compile(store=store)
store.put(("users", "42"), "prefs", {"drink": "tea"})
store.search(("users",), query="what does the user drink?")
License
MIT
Metadata
Release files for piyapi-langchain 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| piyapi_langchain-0.1.1.tar.gz | 19.2 kB | Without provenance | Details for piyapi_langchain-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| piyapi_langchain-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for piyapi_langchain-0.1.1-py3-none-any.whl |
Total release size: 30.7 kB
Release files / piyapi_langchain-0.1.1.tar.gz
| Download URL | piyapi_langchain-0.1.1.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3087754a72ffda68ed53df5ee77f3bc56e2f6bcb5af29befab10c33a0fa0bfdf
|
|
BLAKE2b-256 checksum How to use checksums |
f84aa443adf778c6eac563d9320d4440cfeadf9947fb21058b62b66c2e9357a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.1
|
Release files / piyapi_langchain-0.1.1-py3-none-any.whl
| Download URL | piyapi_langchain-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27cac2b149cb47459a632a629df3ab5cab7bea142ce0aff70e42badf385fdd6a
|
|
BLAKE2b-256 checksum How to use checksums |
2c17301af21ee77eb1b8aa9736d90bd4617c828256c33f16fcc1e64fc4329dca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.1
|
Security for piyapi-langchain 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.