https://github.com/nhogs/nestjs-pinecone
Pinecone module for Nestjs
https://github.com/nhogs/nestjs-pinecone
Last synced: about 1 year ago
JSON representation
Pinecone module for Nestjs
- Host: GitHub
- URL: https://github.com/nhogs/nestjs-pinecone
- Owner: Nhogs
- License: mit
- Created: 2022-05-09T08:30:54.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-13T10:28:13.000Z (almost 4 years ago)
- Last Synced: 2024-10-11T23:19:49.244Z (over 1 year ago)
- Language: TypeScript
- Size: 883 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @nhogs/nestjs-pinecone
[Pinecone.io](https://www.pinecone.io/)
vector database module for nestjs
[](https://github.com/nestjs/nest)
## Installation
[](https://www.npmjs.com/package/@nhogs/nestjs-pinecone)
```bash
$ npm i --save @nhogs/nestjs-pinecone
```
## Usage
See [Pincone quickstart guide](https://www.pinecone.io/docs/quickstart/) for config details
### Use module in NestJS app
```typescript
@Module({
imports: [
PineconeModule.register({
environment: 'YOUR_ENVIRONMENT', // Default is 'us-west1-gcp',
project: 'YOUR_PROJECT', // Project id
apiKey: 'YOUR_API_KEY', // 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
index: 'YOUR_INDEX', // Optional index name
}),
],
})
export class AppModule {}
```
### Async configuration example
```typescript
@Module({
imports: [
PineconeModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService): PineconeConfig => {
return {
index: configService.get('PINECONE_INDEX'),
project: configService.get('PINECONE_PROJECT'),
environment: configService.get('PINECONE_ENV'),
apiKey: configService.get('PINECONE_API_KEY'),
};
},
}),
ConfigModule.forRoot({
envFilePath: './your/env/file/path/.env',
}),
],
})
export class AsyncAppModule {}
```
## Index Operation Service
```typescript
@Injectable()
export class PineconeIndexService {
/**
* Check environment and make sure your Pinecone API key works.
*/
whoAmI(): Observable {}
/**
* This operation returns a list of your Pinecone indexes.
*/
listIndexes(): Observable {}
/**
* Get a description of an index.
* @param indexName or default index set in config
*/
describeIndex(indexName?: string): Observable {}
}
```
## Vector Operation Service
```typescript
@Injectable()
export class PineconeVectorService {
/**
* The DescribeIndexStats operation returns statistics about the index's contents.
* @param index index name
*/
describeIndexStats(index?: string): Observable {}
/**
* The Query operation searches a namespace, using one or more query vectors. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.
* @param query
* @param index
*/
query(query: Query, index?: string): Observable {}
/**
* The Delete operation deletes vectors, by id, from a single namespace. You can delete items by their id, from a single namespace.
* @param del
* @param index
*/
delete(del: Delete, index?: string): Observable {}
/**
* The Fetch operation looks up and returns vectors, by id, from a single namespace. The returned vectors include the vector data and/or metadata.
* @param fetch
* @param index
*/
fetch(fetch: Fetch, index?: string): Observable {}
/**
* The Update operation updates vector in a namespace. If a value is included, it will overwrite the previous value. If a set_metadata is included, the values of the fields specified in it will be added or overwrite the previous value.
* @param update
* @param index
*/
update(update: Update, index?: string): Observable {}
/**
* The Upsert operation writes vectors into a namespace. If a new value is upserted for an existing vector id, it will overwrite the previous value.
* @param upsert
* @param index
*/
upsert(upsert: Upsert, index?: string): Observable {}
}
```
