repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | [pgvector](https://github.com/pgvector/pgvector) is an open-source vector similarity search extension for Postgres. After connecting to Postgres, run `CREATE EXTENSION IF NOT EXISTS vector;` to create the vector extension. |
| #2 | |
| #3 | ### Usage |
| #4 | |
| #5 | <CodeGroup> |
| #6 | ```python Python |
| #7 | import os |
| #8 | from mem0 import Memory |
| #9 | |
| #10 | os.environ["OPENAI_API_KEY"] = "sk-xx" |
| #11 | |
| #12 | config = { |
| #13 | "vector_store": { |
| #14 | "provider": "pgvector", |
| #15 | "config": { |
| #16 | "user": "test", |
| #17 | "password": "123", |
| #18 | "host": "127.0.0.1", |
| #19 | "port": "5432", |
| #20 | } |
| #21 | } |
| #22 | } |
| #23 | |
| #24 | m = Memory.from_config(config) |
| #25 | messages = [ |
| #26 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #27 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #28 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #29 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #30 | ] |
| #31 | m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| #32 | ``` |
| #33 | |
| #34 | ```typescript TypeScript |
| #35 | import { Memory } from 'mem0ai/oss'; |
| #36 | |
| #37 | const config = { |
| #38 | vectorStore: { |
| #39 | provider: 'pgvector', |
| #40 | config: { |
| #41 | collectionName: 'memories', |
| #42 | embeddingModelDims: 1536, |
| #43 | user: 'test', |
| #44 | password: '123', |
| #45 | host: '127.0.0.1', |
| #46 | port: 5432, |
| #47 | dbname: 'vector_store', // Optional, defaults to 'postgres' |
| #48 | diskann: false, // Optional, requires pgvectorscale extension |
| #49 | hnsw: false, // Optional, for HNSW indexing |
| #50 | }, |
| #51 | }, |
| #52 | }; |
| #53 | |
| #54 | const memory = new Memory(config); |
| #55 | const messages = [ |
| #56 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #57 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #58 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #59 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #60 | ] |
| #61 | await memory.add(messages, { userId: "alice", metadata: { category: "movies" } }); |
| #62 | ``` |
| #63 | </CodeGroup> |
| #64 | |
| #65 | ### Config |
| #66 | |
| #67 | Here are the parameters available for configuring pgvector: |
| #68 | |
| #69 | | Parameter | Description | Default Value | |
| #70 | | --- | --- | --- | |
| #71 | | `dbname` | The name of the database | `postgres` | |
| #72 | | `collection_name` | The name of the collection | `mem0` | |
| #73 | | `embedding_model_dims` | Dimensions of the embedding model | `1536` | |
| #74 | | `user` | User name to connect to the database | `None` | |
| #75 | | `password` | Password to connect to the database | `None` | |
| #76 | | `host` | The host where the Postgres server is running | `None` | |
| #77 | | `port` | The port where the Postgres server is running | `None` | |
| #78 | | `diskann` | Whether to use diskann for vector similarity search (requires pgvectorscale) | `True` | |
| #79 | | `hnsw` | Whether to use hnsw for vector similarity search | `False` | |
| #80 | | `sslmode` | SSL mode for PostgreSQL connection (e.g., 'require', 'prefer', 'disable') | `None` | |
| #81 | | `connection_string` | PostgreSQL connection string (overrides individual connection parameters) | `None` | |
| #82 | | `connection_pool` | psycopg2 connection pool object (overrides connection string and individual parameters) | `None` | |
| #83 | |
| #84 | **Note**: The connection parameters have the following priority: |
| #85 | 1. `connection_pool` (highest priority) |
| #86 | 2. `connection_string` |
| #87 | 3. Individual connection parameters (`user`, `password`, `host`, `port`, `sslmode`) |